js jquery分別實(shí)現(xiàn)動態(tài)的文件上傳操作按鈕的添加和刪除
更新時間:2014年01月13日 15:31:12 作者:
本文為大家介紹下使用js及jquery實(shí)現(xiàn)動態(tài)的文件上傳操作按鈕的添加和刪除,具體示例如下,希望對大家有所幫助
javascript實(shí)現(xiàn)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery文件上傳</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
var addMore = function() {
var div = document.getElementById("div2");
var br = document.createElement("br");
var input = document.createElement("input");
var button = document.createElement("input");
input.setAttribute("type", "file");
button.setAttribute("type", "button");
button.setAttribute("value", "Remove");
button.onclick = function() {
div.removeChild(br);
div.removeChild(input);
div.removeChild(button);
}
div.appendChild(br);
div.appendChild(input);
div.appendChild(button);
}
//節(jié)點(diǎn)的移動
//$(function(){
//});
</script>
</head>
<body>
<div id="div1">
<input type="file" id="upload"/>
<input type="button" id="btn" value="more" onclick="addMore();"/>
</div>
<div id="div2"></div>
</body>
</html>
jquery實(shí)現(xiàn)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery文件上傳</title>
<title>jquery1</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
/** var addMore = function() {
var div = document.getElementById("div2");
var br = document.createElement("br");
var input = document.createElement("input");
var button = document.createElement("input");
input.setAttribute("type", "file");
button.setAttribute("type", "button");
button.setAttribute("value", "Remove");
button.onclick = function() {
div.removeChild(br);
div.removeChild(input);
div.removeChild(button);
}
div.appendChild(br);
div.appendChild(input);
div.appendChild(button);
}**/
//jquery實(shí)現(xiàn)文件上傳的按鈕添加和刪除
$(function(){
$("input[type=button]").click(function(){
var br = $("<br>");
var input = $("<input type='file'/>");
var button = $("<input type='button' value='Remove'/>");
$("#div1").append(br).append(input).append(button);
button.click(function() {
br.remove();
input.remove();
button.remove();
});
});
});
</script>
</head>
<body>
<div id="div1">
<input type="file" id="upload"/>
<input type="button" id="btn" value="more" onclick="addMore();"/>
</div>
<div id="div2"></div>
</body>
</html>
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery文件上傳</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
var addMore = function() {
var div = document.getElementById("div2");
var br = document.createElement("br");
var input = document.createElement("input");
var button = document.createElement("input");
input.setAttribute("type", "file");
button.setAttribute("type", "button");
button.setAttribute("value", "Remove");
button.onclick = function() {
div.removeChild(br);
div.removeChild(input);
div.removeChild(button);
}
div.appendChild(br);
div.appendChild(input);
div.appendChild(button);
}
//節(jié)點(diǎn)的移動
//$(function(){
//});
</script>
</head>
<body>
<div id="div1">
<input type="file" id="upload"/>
<input type="button" id="btn" value="more" onclick="addMore();"/>
</div>
<div id="div2"></div>
</body>
</html>
jquery實(shí)現(xiàn)
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery文件上傳</title>
<title>jquery1</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
/** var addMore = function() {
var div = document.getElementById("div2");
var br = document.createElement("br");
var input = document.createElement("input");
var button = document.createElement("input");
input.setAttribute("type", "file");
button.setAttribute("type", "button");
button.setAttribute("value", "Remove");
button.onclick = function() {
div.removeChild(br);
div.removeChild(input);
div.removeChild(button);
}
div.appendChild(br);
div.appendChild(input);
div.appendChild(button);
}**/
//jquery實(shí)現(xiàn)文件上傳的按鈕添加和刪除
$(function(){
$("input[type=button]").click(function(){
var br = $("<br>");
var input = $("<input type='file'/>");
var button = $("<input type='button' value='Remove'/>");
$("#div1").append(br).append(input).append(button);
button.click(function() {
br.remove();
input.remove();
button.remove();
});
});
});
</script>
</head>
<body>
<div id="div1">
<input type="file" id="upload"/>
<input type="button" id="btn" value="more" onclick="addMore();"/>
</div>
<div id="div2"></div>
</body>
</html>
相關(guān)文章
jquery實(shí)現(xiàn)在網(wǎng)頁指定區(qū)域顯示自定義右鍵菜單效果
這篇文章主要介紹了jquery實(shí)現(xiàn)在網(wǎng)頁指定區(qū)域顯示自定義右鍵菜單效果,涉及jquery鼠標(biāo)點(diǎn)擊及事件綁定等相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08jQuery使用animate創(chuàng)建動畫用法實(shí)例
這篇文章主要介紹了jQuery使用animate創(chuàng)建動畫用法,可實(shí)現(xiàn)點(diǎn)擊鏈接文字隱藏及顯示文字的功能,實(shí)例分析了jquery中toggle與animate方法的使用技巧,需要的朋友可以參考下2015-08-08基于jQuery全屏焦點(diǎn)圖左右切換插件responsiveslides
這篇文章主要介紹了基于jQuery全屏焦點(diǎn)圖左右切換插件responsiveslides的相關(guān)資料,需要的朋友可以參考下2015-09-09jQuery+AJAX實(shí)現(xiàn)遮罩層登錄驗(yàn)證界面(附源碼)
這篇文章主要介紹了jQuery+AJAX實(shí)現(xiàn)遮罩層登錄驗(yàn)證界面,并分享了源碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-10-10jquery實(shí)現(xiàn)彈出層登錄和全屏層注冊特效
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)彈出層登錄和全屏層注冊特效,推薦給大家,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-08-08