JavaScript 通过jquery.qrcode生成二维码
通过jquery.qrcode生成二维码
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Qrcode</title>
<!-- https://code.jquery.com/ -->
<script type="text/javascript" src="./jquery-1.12.4.min.js"></script>
<!-- https://github.com/jeromeetienne/jquery-qrcode -->
<script type="text/javascript" src="./jquery.qrcode.min.js"></script>
</head>
<body>
<div id="qrcode1"></div>
<div id="qrcode2"></div>
<div id="qrcode3"></div>
<script type="text/javascript">
/**
* 生成二维码
*/
$('#qrcode1').qrcode("https://blog.csdn.net/qcl108");
/**
* 生成二维码
* width: 宽度
* height: 高度
*/
$('#qrcode2').qrcode(
{
width: 120,
height: 120,
text: "size doesn't matter"
}
);
/**
* 内容包含中文需要先转换
*/
function toUtf8(str) {
var res = '', len = str.length;
for(var i = 0; i < len; i++) {
var c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)){
res += str.charAt(i);
} else if (c > 0x07FF) {
res += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
res += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
res += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else{
res += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
res += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return res;
}
/**
* 生成内容包含中文的二维码
*/
$('#qrcode3').qrcode(
{
width: 120,
height: 120,
text: toUtf8("生成二维码 https://blog.csdn.net/qcl108")
}
);
</script>
</body>
</html>
如果您觉得有帮助,欢迎点赞哦 ~ 谢谢!!