js多文件下载

 1         $('#download').click(function(){
 2             var arr = []
 3             $('.file').each(function(index){
 4                 arr.push($(this).text())
 5             })
 6             var brr = []
 7             $('.file').each(function(index){
 8                 brr.push($(this).data('url'))
 9             })
10 
11             for(var a=0;a<arr.length;a++){
12                 for(var b=0;b<brr.length;b++){
13                     if(a==b){
14                         download(arr[a],brr[b]);
15                     }
16                 }
17             }
18         })
19         function download(name, href) {
20             var a = document.createElement("a"),
21                 e = document.createEvent("MouseEvents");
22             e.initEvent("click", false, false);
23             a.href = href;
24             a.download = name;
25             a.dispatchEvent(e);
26         }

 

posted @ 2022-04-09 11:05  桓台彭于晏  阅读(540)  评论(0)    收藏  举报