实现点击下载到本地的功能

新建一个a标签,设置不显示在页面中,download属性,添加给body,并在下载后移除

var alink = document.creatElement('a')
alink.style.display = 'none'
alink.href = fileURL
alink.setAttribute("download", '文件名.txt')
document.body.appendChild(alink)
alink.click()
document.body.removeChild(alink)
window.URL.revokeObjectURL(fileURL) //释放

 

posted @ 2020-07-26 16:48  ashen1999  阅读(267)  评论(0编辑  收藏  举报