js实现图片下载

<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>

 

posted @ 2018-09-05 10:36  山上小和尚  阅读(262)  评论(0编辑  收藏  举报