Using jquery. qrcode to generate a QR code online _ jquery-js tutorial

Source: Internet
Author: User
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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.