Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use jquery.qrcode to generate QR Code

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use jquery.qrcode to generate QR code, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Qrcode actually uses jQuery to render graphics, draw pictures, and supports canvas (HTML5) and table. You can go to https://github.com/jeromeetienne/jquery-qrcode to get the latest code.

How to use

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

2. Add the following code where the QR code needs to be displayed on the page:

3. Call the qrcode plug-in.

Qrcode supports both canvas and table for image rendering. Canvas is used by default, which is the most efficient. Of course, the browser supports html5. Call directly as follows:

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

You can also call the following ways:

$("# code") .qrcode ({render: "table", / / table mode width: 200, / / width height:200, / / height text: "www.xuebuyuan.com" / / anything})

In this way, you can generate a QR code directly in the page, and you can use the "scan" function to read the QR code information.

Identify Chinese

During the experiment, we found that the QR code which could not recognize the Chinese content, by looking for multi-party data, we learned that jquery-qrcode uses charCodeAt () for coding conversion. This method acquires its Unicode code by default. If there is any Chinese content, convert the string to UTF-8 before generating the QR code, and then generate the QR code. You can convert Chinese strings through the following functions:

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 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;}

The following example:

Var str = toUtf8 ("Diaoyu Islands are Chinese!") ; $('# code') .qrcode (str). The above is all the contents of the article "how to generate a QR Code using jquery.qrcode". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report