Use the jquery plug-in qrcode to generate a QR code, and the jquery plug-in qrcode

Source: Internet
Author: User

Use the jquery plug-in qrcode to generate a QR code, and the jquery plug-in qrcode

The QR code application has penetrated into our daily work and life. You only need to scan the QR code on your mobile phone to obtain the corresponding information, so that we can learn about Sellers, shopping, and watching movies. This article describes a jquery-based QR code generation plug-in qrcode. You can call this plug-in on the page to generate the corresponding QR code.
Qrcode uses jQuery to implement graphic rendering and drawing. It supports canvas (HTML5) and table methods. You can obtain the latest code.

How to Use
1. First, add the jquery library file and qrcode plug-in to the page.

<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.qrcode.min.js"></script> 

2. Add the following code to the page where you need to display the QR code:

<div id="code"></div> 

3. Call the qrcode plug-in.
Qrcode supports canvas and table for Image Rendering. By default, the canvas mode is used, with the highest efficiency. Of course, the browser must support html5. The direct call is as follows:

$ ('# Code'). qrcode ("http://www.bkjia.com"); // any string

You can also call the following method:

$ ("# Code "). qrcode ({render: "table", // table mode width: 200, // width height: 200, // height text: "http://www.bkjia.com" // any content });

In this way, you can directly generate a QR code on the page. You can use the "scan" function on your mobile phone to read the QR code information.
Recognize Chinese
During the experiment, we found that the two-dimensional code could not recognize Chinese content. We found that jquery-qrcode was converted using charCodeAt. 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 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 += 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;  } 

Example:

Var str = toUtf8 ("helper house! "); $ ('# Code'). qrcode (str );

Currently, there are a lot of tutorials on how to create QR codes on the Internet. You must learn how to use them flexibly and use your favorite method to learn how to create QR codes.

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.