js脚本在html中批量加入图片,我们需要设置一个父类的div,然后在创建子类,在创建好一个img的子类,将图片都添加进来,
<html>
<body>
<div id='parent'>
<div class='pin'>
</div>
</div>
</body>
<script>
var oPin = document.createElement('div')
oPin.className = 'pin'
oParent.appendChild(oPin)
var oImg = document.createElement('img')
loadImg('./image/'+ data[i].src,callBack,oImg) //这里是你的图片地址
oImg.src = './image/'+ data[i].src
oPin.appendChild(oImg)
</script>
</html>
js没有操作本地文件的权限,可以借助.net,php等后端语言才行的,将图片提交之后,返回个下载地址,window.open就自动下载了。但是图片可以是svg的话
function saveAs(Url,filename){
var blob=new Blob([''], {type:'application/octet-stream'})
var url = webkitURL.createObjectURL(blob)
var a = document.createElementNS(xhtml,'a')
a.href = Url
a.download = filename
var e = document.createEvent('MouseEvents')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
webkitURL.revokeObjectURL(url)
2. saveAs(data,"new.svg")