文章内容
一、首先在页面中加入jquery库文件和qrcode插件
1 2 | < script type = "text/javascript" src = "jquery.js" ></ script > < script type = "text/javascript" src = "jquery.qrcode.min.js" ></ script > |
二、页面添加标签
1 | < div id = "code" ></ div > |
三、调用qrcode插件。支持canvas和table两种方式进行图片渲染
1、canvas方式
1 |
2、table方式
1 2 3 4 5 6 | $( "#code" ).qrcode({ render: "table" , //table方式 width: 200, //宽度 height:200, //高度 text: "www.baidu.com" //任意内容 }); |
四、UTF-8转码
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 | 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; } |