Go straight to the chase:
The introduction of jquery js and Jquery-qrcode.js, I will later upload the code demo to the repository. The code is simple:
If non-Chinese characters Fuzhou into two-dimensional code, then it is relatively simple.
<! DOCTYPE html>
If it is a Chinese character or contains Chinese characters, then you need to do some encoding conversion to convert UTF-16 to UTF-8
<! DOCTYPE html>
The contents of Convertcn.js are as follows:
function Utf16to8 (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 > 0x07 FF) {out + = String.fromCharCode (0xE0 | ((c >> b) & 0x0F)); O UT + = String.fromCharCode (0x80 | ((c >> 6) & 0x3F)); O UT + = String.fromCharCode (0x80 | ((c >> 0) & 0x3F));} else {out + = String.fromCharCode (0xC0 | ((c >> 6) & 0x1F)); O UT + = String.fromCharCode (0x80 | ((c >> 0) & 0x3F);}} return out;}
The introduction of the third JS is customized to solve the problem of Chinese unrecognized. jquery is faster, easier, and more dependent on fewer plugins than Java Servlets generate two-dimensional code.
jquery generates two-dimensional code