js实现给定图片路径自动下载

js实现图片自动下载

1.添加img标签

<img id='downImg' src='' style='display: none;' />

2.调用方法download

    //图片路径
    var src = './1.png';
    //下载保存文件名
    var imgname = 'testImg.jpg';

    function download(src,imgname) {
        $('#downImg').attr('src', src);
        var img = $('#downImg').attr("src");
        var alink = document.createElement("a");
        alink.href = img;
        alink.download = imgname;
        alink.click();
    }

You may also like...

1 Response

  1. zoritoler imol说道:

    Your place is valueble for me. Thanks!…

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

CAPTCHAis initialing...
退出移动版