1. 程式人生 > >js生成二維碼

js生成二維碼

rom 生成二維碼 length else 通過 class code ring tab

首先通過引入jq的插件庫 --jquery.min.js --jquery.qrcode.min.js 接著就比較簡單了 準備好盛放二維碼的容器 直接上代碼 $(function(){ var str = toUtf8(‘123132132123‘); //imgcode為存放二維碼的容器 $(".imgcode").html(‘‘); $(".imgcode").qrcode({ render: "table", width: 200, height:200, 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; }

js生成二維碼