【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
<!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/libin-1/p/5836108.html
来源:oschina
链接:https://my.oschina.net/u/3621360/blog/3051884