这是一段使用 JavaScript 写的点击下载文件的代码:
function downloadFile(fileUrl) {
var link = document.createElement('a');
link.href = fileUrl;
link.download = fileUrl.substr(fileUrl.lastIndexOf('/') + 1);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
你可以将文件的 URL 作为参数传递给这个函数,然后点击下载按钮调用这个函数即可实现下载。
例如&#x