//This is the html part //This is the html part

Home  >  Article  >  Web Front-end  >  Two ways to generate QR codes using javascript

Two ways to generate QR codes using javascript

一个新手
一个新手Original
2017-09-20 09:43:182162browse

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.

qrcodeQR code

<p id="qrcode"></p>//这个是html部分<a id="download" download="test.jpg"></a>
<input type="button" id="down" value="下载">
var qrcode = new QRCode(document.querySelector(&#39;#qrcode&#39;),{
        width  : 96,//设置二维码的宽高
        height : 96
    });
   qrcode.makeCode("http://www.baidu.com/");//按地址生成二维码
    var url = $(&#39;#qrcode canvas&#39;).toDataURL(&#39;image/jpeg&#39;);    //转成jpg图片
    $(&#39;#down&#39;).click(function(){
         $("#download").attr(&#39;href&#39;, url);
    })//下载

jquery.qrcode

    <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(&#39;#qrcode&#39;).qrcode({width: 96,height: 96,text:"http://www.baidu.com"});

    $("#save").click(function(){

        var canvas = $(&#39;#qrcode&#39;).find("canvas").get(0);        var url = canvas.toDataURL(&#39;image/jpeg&#39;);

        $("#download").attr(&#39;href&#39;, 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn