codepen: https://codepen.io/linqingwudiv1/pen/ydrXgE
代码:
function downloadURI(uri, name) { var link = document.createElement("a"); link.download = name; link.href = uri; document.body.appendChild(link); link.click(); document.body.removeChild(link); delete link; }; window.onload = function () { console.log(‘onload‘); let qrcode = new QRCode(document.getElementById("qrcode"), { text: "http://www.runoob.com", width: 450, height: 450, colorDark : "#000000", colorLight : "#ffffff", correctLevel : QRCode.CorrectLevel.H }); setTimeout( function () { let dataUrl = document.querySelector(‘#qrcode‘).querySelector(‘img‘).src; downloadURI(dataUrl, ‘qrcode.png‘); } ,1000); };
原文:https://www.cnblogs.com/linqing/p/11178233.html