function downloadIamge(selector, name) {
// 通过选择器获取img元素,
var img = document.querySelector(selector)
// 将图片的src属性作为URL地址
var url = img.src
var a = document.createElement('a')
巧皮搏 var event = new MouseEvent('孝祥click')
a.download = name || '下载图片名称'
a.href = url
a.dispatchEvent(event)
}
<握凯img src="1.jpg" class="img1">