1

我想压缩下载一个文件夹。我似乎无法找出如何。JSZip 似乎只下载文件。

我不想使用 PHP。

最后一件事,我希望它通过链接下载,例如 <a href='#'>Download</a>。

4

1 回答 1

0

继续调用 zip.file()。看看他们的例子http://stuk.github.io/jszip/

例如如下:

var zip = new JSZip();

// Add a text file with the contents "Hello World\n"
zip.file("Hello.txt", "Hello World\n");

// Add a another text file with the contents "Goodbye, cruel world\n"
zip.file("Goodbye.txt", "Goodbye, cruel world\n");

// Add a folder named "images"
var img = zip.folder("images");

// Add a file named "smile.gif" to that folder, from some Base64 data
img.file("smile.gif", imgData, {base64: true});

var content = zip.generate();
location.href="data:application/zip;base64,"+content;

重要的是理解你编写的代码——了解每一行的作用。如果你这样做,你会意识到你只需要再次调用 zip.file() 来添加另一个文件。

于 2016-06-03T23:59:04.703 回答