我想改变的值download
与javascript属性,我试图用download
一个的属性附加伤害<a>
标签。但是我不知道如何在其中包含JavaScript download
?
<a href="REALFILENAME.txt" download="JAVASCRIPT_FUNCTION_HERE">CLICK ME</a>
function getDownloadName(){
return "REALFILENAME_" + new Date().getTime();+ ".txt";
}
谢谢!
您可以通过使用setAttribute设置download属性来做到这一点,如下所示:
function getDownloadName(){
return "REALFILENAME_" + new Date().getTime();+ ".txt";
}
function setDownloadAttribute() {
var a = document.getElementById("fileLink");
a.setAttribute("download", getDownloadName())
}
var a = document.getElementById("fileLink");
a.onclick = setDownloadAttribute;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句