js二維碼生成外掛“jquery.qrcode.min.js”
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>生成二維碼</title>
<script type='text/javascript' src='http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js'></script>
<script type="text/javascript" src="http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
</head>
<body>
<div id="qrcode"></div>
</body>
<script>
//如果內容中有中文,在生成二維碼錢就要把字串轉換成utf-8 可防止掃描二維碼中文亂碼
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;
}
$("#qrcode").qrcode({
render: "table", //也可以替換為canvas,table
width:168, //二維碼寬度
height:168, //二維碼高度
text: toUtf8('我是tianma')
})
</script>
</html>
優秀參考連結 http://www.cnblogs.com/l