First, basic use
Plugin Address: Https://github.com/jeromeetienne/jquery-qrcode
1. First add the jquery library file and the QRCode plugin 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 where you want the QR code to appear in the page:
<div id="code"></div>
3, call QRCode plug-in.
QRCode supports canvas and table two ways of rendering pictures, the default use of canvas, the most efficient, of course, the browser supports HTML5. The direct invocation is as follows:
$ (' #code '). QRCode (" this plugin is great // arbitrary string
It can also be called in the following ways:
$ ("#code"). QRCode ({ / ///// Text: " this plugin is great // any Content
});
Ii. Recognition of Chinese
The Jquery-qrcode is encoded using the charCodeAt () method. 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:
functionToUtf8 (str) {varOut , 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 >> 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)); } } returnOut ; }
The following example:
var str = ToUtf8 ("The plugins is great." This plugin is good! "); $(
js-jquery-Two-dimensional code