您好,欢迎访问一九零五行业门户网

JavaScript动态数量的文件上传控件

js动态数量的文件上传控件实现代码如下所述:
<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>动态数量的文件上传</title> <script type="text/javascript" src="jquery-2.2.0.min.js"> </script><script type="text/javascript"> $(function(){ var i=2; $("#addfile").click(function(){ $(this).parent().parent().before("<tr class='file'><td>file" +i+":</td><td><input type='file' name='file" +i+"'/></td></tr>" +"<tr class='desc'><td>desc" +i+":</td><td><input type='text' name='desc" +i+"'/><button id='delete" +i+"'>删除</button></td></tr>"); i++; //删除 $("#delete"+(i-1)).click(function(){ var $tr=$(this).parent().parent(); $tr.prev("tr").remove(); $tr.remove(); //对i排序 $(".file").each(function(index){ var n=index+1; $(this).find("td:first").text("file"+n); $(this).find("td:last input").attr("name","file"+n); }); $(".desc").each(function(index){ var n=index+1; $(this).find("td:first").text("desc"+n); $(this).find("td:last input").attr("name","desc"+n); }); }); }); }); </script> </head> <body> <table> <tr class="file"> <td>file1:</td> <td><input type="file" name="file1"/></td> </tr> <tr class="desc"> <td>desc1:</td> <td><input type="text" name="desc1"/></td> </tr> <tr> <td><input type="submit" id="submit" value="上传"/></td> <td><button id="addfile">增加</button></td> </tr> </table> </body> </html>
好了,代码到此结束了,希望对大家有所帮助
其它类似信息

推荐信息