我是靠谱客的博主 美满小兔子,这篇文章主要介绍JavaScript动态数量的文件上传控件,现在分享给大家,希望可以做个参考。

js动态数量的文件上传控件实现代码如下所述:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!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>

好了,代码到此结束了,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的,在此也非常感谢大家对脚本之家网站的支持!

最后

以上就是美满小兔子最近收集整理的关于JavaScript动态数量的文件上传控件的全部内容,更多相关JavaScript动态数量内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(157)

评论列表共有 0 条评论

立即
投稿
返回
顶部