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; }