首先通过引入jq的插件库
--jquery.min.js
--jquery.qrcode.min.js
接着就比较简单了
准备好盛放二维码的容器
直接上代码
$(function(){
var str = toUtf8(‘123132132123‘);
//imgcode为存放二维码的容器
$(".imgcode").html(‘‘);
$(".imgcode").qrcode({
render: "table",
width: 200,
height:200,
text: str
});
})
//函数是关键,看不懂没关系直接调用就好了
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 += 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;
}