jQuery:

function download(src) {
var $a = $("").attr("href", src).attr("download", "img.png");
$a[0].click();
}
原生js:

function download(src) {
var $a = document.createElement('a');
$a.setAttribute("href", src);
$a.setAttribute("download", "");

var evObj = document.createEvent('MouseEvents');
evObj.initMouseEvent( 'click', true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null);
$a.dispatchEvent(evObj);

};

相关文章:

  • 2022-12-23
  • 2022-02-01
  • 2021-09-03
  • 2021-08-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-03
  • 2021-05-19
  • 2021-05-26
  • 2021-11-27
  • 2022-12-23
  • 2022-02-16
  • 2021-11-18
相关资源
相似解决方案