Home > Web Front-end > JS Tutorial > body text

Two ways to generate QR codes using javascript

一个新手
Release: 2017-09-20 09:43:18
Original
2143 people have browsed it

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="下载">
Copy after login
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);
    })//下载
Copy after login

jquery.qrcode

    <p id="qrcode"></p>
    <a id="download" download="test.jpg"></a>
    <input type="button" id="save" value="save" />
Copy after login
<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;
    });
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!