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

Example of using jquery.qrcode to generate QR code online_jquery

WBOY
Release: 2016-05-16 17:24:48
Original
1202 people have browsed it

I have been working on a QR code project recently, so I found this when I was casually looking at it. It feels good. In addition to its own excellent js functions, jquery also comes with countless plug-ins, which can achieve various beautiful effects and functions. jquery.qrcode is one of them, used to generate QR codes online.
The open source address of the qrcode plug-in on github is https://github.com/jeromeetienne/jquery-qrcode
It comes with instructions for use at the back, only four simple steps, very convenient to call.

The plug-in is written by foreigners, so it cannot recognize the QR code of Chinese content when it is first used, because jquery.qrcode itself uses the charCodeAt() method for encoding conversion. This method will obtain its Unicode encoding by default. If there is Chinese content, the string must be converted to UTF-8 before generating the QR code, and then the QR code will be generated. You can add the following function to the page to convert Chinese strings:

Copy the code The code is as follows:

function toUtf8(str) {
var out, i, len, c;
out = "";
len = str.length;
for(i = 0; i < len ; i ) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out = str.charAt(i);
} else if (c > 0x07FF) {
out = String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out = String.fromCharCode(0x80 | ( (c >> 6) & 0x3F));
out = String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out = String .fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out = String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}
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!