I only know two ways to generate QR codes with js, which can be downloaded. I tried the first one, which could not be downloaded, but I can still download it. It is basically the same as the second method.
<p id="qrcode"></p>//这个是html部分<a id="download" download="test.jpg"></a> <input type="button" id="down" value="下载">
var qrcode = new QRCode(document.querySelector('#qrcode'),{ width : 96,//设置二维码的宽高 height : 96 }); qrcode.makeCode("http://www.baidu.com/");//按地址生成二维码 var url = $('#qrcode canvas').toDataURL('image/jpeg'); //转成jpg图片 $('#down').click(function(){ $("#download").attr('href', url); })//下载
<p id="qrcode"></p> <a id="download" download="test.jpg"></a> <input type="button" id="save" value="save" />
<script src="js/jquery.qrcode.min.js"></script> jQuery('#qrcode').qrcode({width: 96,height: 96,text:"http://www.baidu.com"}); $("#save").click(function(){ var canvas = $('#qrcode').find("canvas").get(0); var url = canvas.toDataURL('image/jpeg'); $("#download").attr('href', url).get(0).click(); return false; });
I only know two types of js-generated QR codes, which can be downloaded. The first one cannot be downloaded by me. After trying it, I can still download it. It is basically the same as the second method.
The above is the detailed content of Two ways to generate QR codes using javascript. For more information, please follow other related articles on the PHP Chinese website!