js实现图片下载

180it 2020-04-05 PM 1471℃ 0条
<img  src='src' data-name='自定义名称'>
<script>
//js实现图片下载
function download(){
        var name = $('#downImg').attr("data-name");
        var url = $('#downImg').attr("src");
        var a = document.createElement('a')  
        var event = new MouseEvent('click')  
        a.download = name || '下载图片名称'  
        a.href = url  
        a.dispatchEvent(event)  
}
</script>
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

js实现图片下载