jQuery动态添加 input type=file的实现代码
发布时间:2013-05-23 编辑:jiaochengji.com
有时候需要在页面上允许用户上传多个文件,个数由用户自己决定,个数多了也可以删除,使用jQuery可以很简单的实现这个功能
有时候需要在页面上允许用户上传多个文件,个数由用户自己决定,个数多了也可以删除,使用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/
复制代码 代码如下:
<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/
您可能感兴趣的文章:
jQuery动态添加 input type=file的实现代码
js与jquery动态文件上传实现代码
js jquery分别实现动态的文件上传操作按钮的添加和删除
基于Jquery的动态添加控件并取值的实现代码
jquery 动态加载js的多种方法汇总
JS动态添加与删除控件的代码一例
如何使用jquery动态加载js,css文件实现代码
Struts2的s:radio标签使用及用jquery添加change事件
js 动态增加file实现多文件上传功能
jQuery动态添加、删除元素的方法
[关闭]