In addition to its outstanding js functions, jquery also comes with countless plug-ins to complete a variety of good effects and functions. Jquery. qrcode is one of them, which is used to generate a QR code online. Recently, we are working on a QR code project, so we can see that this is quite good. In addition to its outstanding js functions, jquery also comes with countless plug-ins to complete a variety of good effects and functions. Jquery. qrcode is one of them, which is used to generate a QR code online.
Qrcode plug-in on github Open Source Address in https://github.com/jeromeetienne/jquery-qrcode
It is accompanied by instructions for use. It can only be called in four simple steps.
The plug-in is written by foreigners, so the QR code of Chinese content cannot be recognized at the beginning of use, because jquery. qrcode itself uses charCodeAt () for encoding conversion. And this method will get its Unicode encoding by default, if there is Chinese content, in the generation of the QR code before the string to the UTF-8, and then generate a QR code. You can add the following functions on the page to convert Chinese strings:
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;
}