将网址生成随机二维码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery生成QRCode二维码</title>
<link rel="icon" href="https://qiniu.haomachina.cn/uploads/20230205/0bc895e97df2c036bda990ae3cb202d9.jpg">
<script src="https://cdn.bootcss.com/jquery/3.3.0/jquery.min.js"></script>
<script src="https://blog-static.cnblogs.com/files/lovling/jquery.qrcode.js"></script>
<style>
body {
height: 100%;
width: 100%;
}
#qrcode-2 {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<!-- 存放二维码 -->
<div id="qrcode-2"></div>
<script>
// 中文编码
function utf16to8(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;
}
// 随机生成二维码
function createQrcode() {
// 进行路径中文编码
var qcode = utf16to8('http://b.nmgca.com/index/index/wxlogin.html?business_id=1&tourl=http://192.168.8.98/im/text/15I8l4.html')
$('#qrcode-2').html("")
var q = $('#qrcode-2').qrcode({
// render: "canvas",
width: 228, //二维码宽度
height: 228, //二维码高度
typeNumber: -1,//计算模式
correctLevel: 2,//二维码纠错级别
background: "#ffffff",//背景颜色
foreground: "#000000", //二维码颜色
text: qcode,
src: 'https://qiniu.haomachina.cn/uploads/20230205/0bc895e97df2c036bda990ae3cb202d9.jpg'
})
}
createQrcode();
</script>
</body>
</html>