Home  >  Article  >  Web Front-end  >  How does the qrcode.js plug-in generate QR codes?

How does the qrcode.js plug-in generate QR codes?

零到壹度
零到壹度Original
2018-03-23 12:03:281628browse


This article mainly shares with you how the qrcode.js plug-in generates QR codes, mainly in the form of code. I hope it can help everyone.

1.github download address

## https://github.com/jeromeetienne/jquery- qrcode

2. Use case

QR code link jump, carrying Chinese parameters

<span style="font-size: 14px;"><!DOCTYPE HTML ><br/><html lang="en" ><br/><head><br/>    <meta charset="UTF-8"><br/>    <title>Title</title><br/>    <script type="text/javascript" src="jquery-3.2.1.min.js"></script><br/>    <script type="text/javascript" src="jquery.qrcode.min.js"></script><br/></head><br/><body><br/>    <p id="qrcode"></p><br/><br/>    <script><br/>        var str = toUtf8("https://www.baidu.com/s?wd=csdn论坛");<br/><br/>        //qrcode支持canvas和table两种方式进行图片渲染<br/>        $(&#39;#qrcode&#39;).qrcode({<br/>            render: "canvas", //默认是canvas渲染,可以设置为table<br/>            width:100,<br/>            height:100,<br/>            text: str<br/>        });<br/><br/>        //处理中文乱码<br/>        function toUtf8(str) {<br/>            var out, i, len, c;<br/>            out = "";<br/>            len = str.length;<br/>            for(i = 0; i < len; i++) {<br/>                c = str.charCodeAt(i);<br/>                if ((c >= 0x0001) && (c <= 0x007F)){<br/>                    out += str.charAt(i);<br/>                } else if (c > 0x07FF) {<br/>                    out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));<br/>                    out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));<br/>                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));<br/>                } else{<br/>                    out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));<br/>                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));<br/>                }<br/>            }<br/>            return out;<br/>        }<br/>    </script><br/></body><br/></html><br/></span>

Related links:

JS/JQ generate QR code plug-in

qrious.js realizes online generation of QR code plug-in

JS QR code generation plug-in

The above is the detailed content of How does the qrcode.js plug-in generate QR codes?. 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