jQuery动态添加 input type=file的实现代码

 更新时间:2012年06月14日 19:23:44   作者:  
有时候需要在页面上允许用户上传多个文件,个数由用户自己决定,个数多了也可以删除,使用jQuery可以很简单的实现这个功能

复制代码 代码如下:

<form id="fileForm" action="" method="post" enctype="multipart/form-data">
<tr>
<td>
<input type="file" name="file"><input type="button" id="addButon" value="Add" onclick="add()">
</td>
</tr>
</form>

核心jquery代码
复制代码 代码如下:

//添加一行<tr>
function add() {
var content = "<tr><td>";
content += "<input type='file' name='file'><input type='button' value='Remove' onclick='remove(this)'>";
content += "</td></tr>"
$("#fileForm").append(content);
}
//删除当前行<tr>
function remove(obj) {
$(obj).parent().parent().remove();
}


脚本之家整理的在线演示:http://demo.jb51.net/jquery/juqery_input/

相关文章

最新评论