当前位置: 代码迷 >> 综合 >> jQuery qrcode生成二维码
  详细解决方案

jQuery qrcode生成二维码

热度:98   发布时间:2023-09-29 04:32:13.0

1、头部导入js

<script src="/static/js/main/jquery-3.3.1.min.js"></script>
<script src="/static/js/dist/jquery.qrcode.min.js"></script>

2、代码实现

/*** 生成二维码* @param cla 标签class名* @param id 业务数据主键*/
function encode(cla,id){var str=SERVER_URL+"/main/index.html?address_id=" + id;str=toUtf8(str);$("."+cla+"").qrcode({render: "canvas", //table方式width: 300, //宽度height:300, //高度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;
}
  相关解决方案