The function of two-dimensional code
1) mobile device sweep, easy to "take" reading (that is, the URL to generate a two-dimensional code)
2) information can be passed (simply generate a QR code)
Third-party Open source libraries
Project Source: Https://github.com/jeromeetienne/jquery-qrcode
Qrcode.js Core Function Library of two-dimensional code implementation
Jquery.qrcode.js uses jquery to encapsulate the core library of functions. Using it to achieve graphical rendering is actually drawing (supports canvas and table two ways).
How to use
1) Introduction of the jquery Library
2) Introduction of Qrcode.js
3) Introduction of Jquery.qrcode.js
4) Write
var str = "http://www.baidu.com";//var str = "Hello world";//var str = "Chinese to add a function";//var str = ToUtf8 (str); Some functions are to solve the Chinese garbled $ ("#qrcode"). QRCode ({render: "canvas",//Set render mode, value "Canvas" or "table", omitted as "canvas" text:str,//unique required fields, QR Code information width:200,//wide, omitted to 256pxheight:200,//high, omitted to 256pxbackground: "#fff",//two-D code background color, omitted to #fffforeground: "#0f0"//two-D code foreground color, Omit to #000
Solve Chinese garbled characters
Jquery.qrcode.js This library is encoded using the charCodeAt () method, which by default obtains its Unicode encoding. So the Chinese will be garbled, the solution is to put the following function in Qrcode.js last.
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; }
Using Jquery.qrcode.js to generate large-size QR code