When using jquery.qrcode.js, this plugin generates a QR code that does not recognize Chinese.
The reason is thatjquery-qrcode is encoded by charCodeAt ().
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.
Workaround:
Use the following function 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 ; }
Then you can use it again.
var str = ToUtf8 ("Diaoyu Islands are Chinese!") "); $(
Create a QR code of JQuery plugin: Jquery.qrcode.js's Chinese garbled problem