有没有办法使用<a>带有"下载"属性的标签进行批量下载?



download添加到<a>标记时,用户可以在单击链接时下载文件,而不是转换到URL。

<a href="http://www.example.com/index.html" download>Download</a>

但是有办法进行批量下载(多个文件(吗?提前感谢!

没有办法通过纯HTML下载多个文件。您也许可以使用javascript下载这些文件:

var links = ['file1.pdf', 'file2.jpg'] // Change with file paths
for (let filename in links) {
var element = document.createElement('a');
element.setAttribute('href', '/'+links[filename]);
// Change 'file' to something else to change the name of the downloaded file
element.setAttribute('download', 'file');
// Optionally, hide the element before appending, so that the user doesn't download the file again.
document.body.appendChild(element)
element.click() // This will prompt the user to download
}

最新更新