前端直接打包导出ZIP 文件 ,无需后台交互。 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <script src="http://stuk.github.io/jszip/dist/jszip.js"></script> <script type="text/javascript" src="http://stuk.github.io/jszip-utils/dist/jszip-utils.js"></script> <!--[if IE]> <script type="text/javascript" src="http://stuk.github.io/jszip-utils/dist/jszip-utils-ie.js"></script> <![endif]--> <script src="http://stuk.github.io/jszip/test/jquery-1.8.3.min.js"></script> <script src="http://stuk.github.io/jszip/vendor/FileSaver.js"></script> </head> <body> <script> var imgData = "R0lGODdhBQAFAIACAAAAAP/eACwAAAAABQAFAAACCIwPkWerClIBADs="; var zip = new JSZip(); zip.file("Hello.txt", "Hello World\n"); var img = zip.folder("images"); img.file("smile.gif", imgData, {base64: true}); zip.generateAsync({type:"blob"}).then(function(content) { // see FileSaver.js saveAs(content, "example.zip"); }); </script> </body> </html>
前端JSZIP库的使用
最新推荐文章于 2024-06-30 16:24:04 发布