本文主要和大家分享qrcode.js插件如何生成二维码,主要以代码形式,希望能帮助到大家。
1.github下载地址
https://github.com/jeromeetienne/jquery-qrcode
2.使用案例 二维码链接跳转,携带中文参数
<!doctype html >
<html lang="en" >
<head>
<meta charset="utf-8">
<title>title</title>
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="jquery.qrcode.min.js"></script>
</head>
<body>
<p id="qrcode"></p>
<script>
var str = toutf8("https://www.baidu.com/s?wd=csdn论坛");
//qrcode支持canvas和table两种方式进行图片渲染
$('#qrcode').qrcode({
render: "canvas", //默认是canvas渲染,可以设置为table
width:100,
height:100,
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;
}
</script>
</body>
</html>
相关链接:
js/jq生成二维码插件
qrious.js实现在线生成二维码插件
js二维码生成插件
以上就是qrcode.js插件如何生成二维码的详细内容。