在a标签的src路径末尾加上:?response-content-type=application/octet-stream 就可以下载图片了
<html>
<head>
<meta name="layout" content="main">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<img style="width: 300px;height: 300px;"
src="https://wallpaper-static.cheetahfun.com/wallpaper/sites/beauty/pic1.jpg" width="90%" id="testImg">
<button id="saveImg"style="margin-left:20px;margin-top:20px;">保存图片</button>
</body>
</html>
<script>
saveImg.onclick = () => {
var img = document.getElementById("testImg");
var alink = document.createElement("a");
alink.href = img.src + '?response-content-type=application/octet-stream';
alink.click();
}
</script>