Generate two-dimensional code, two-dimensional code generation

Source: Internet
Author: User
Tags jquery library

This article introduces a jquery-based QR code generation plug-in QRCode, which can generate the corresponding QR code by invoking the plugin on the page.

1. First add the jquery library file and the QRCode plugin to the page.

2. Add a div to the page layout

   <div class= "Modal-body" id= "QRCode" style= "left:40px" >    </div>

3, call QRCode plug-in.

4, we found that the test can not recognize the Chinese content of the two-dimensional code, through the search for a number of data learned that Jquery-qrcode is the use of charCodeAt () method of encoding conversion. This method will get its Unicode encoding by default, and if it has Chinese content, it will convert the string to UTF-8 before generating the QR code, and then generate the QR code. You can use the following functions to convert Chinese strings:

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                + = S Tring.fromcharcode (0xE0 | ((c >> b) & 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;    

This method can be written directly into the referenced plug-in, directly after the call. As follows:


Generate two-dimensional code, two-dimensional code generation

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: 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.