jquery.qrcode.js 生成二维码并支持中文的方法

2022-10-22,,,,

GitHub地址: https://github.com/jeromeetienne/jquery-qrcode

    <div class="QR"></div>            

    jQuery('.QR').qrcode({//QR填充二维码的div
//render:'table',
render:'canvas',
width : 200,
height : 200,
text : utf16to8("这里填写二维码显示内容, 可以是文字, 也可以是url"),//中文文字需要转换
//text : url,// url不用转换,直接使用
typeNumber:-1,//计算模式
correctLevel:2,//二维码纠错级别
/* background:"#ffffff",//背景颜色
foreground:"#000000" //二维码颜色
*/
});
//二维码中的中文转换
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 > 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;
}

jquery.qrcode.js 生成二维码并支持中文的方法的相关教程结束。

《jquery.qrcode.js 生成二维码并支持中文的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。