1. 程式人生 > >url地址生成二維碼

url地址生成二維碼

$(function(){ //此處生成名片二維碼 var the_text = utf16to8("https://u.wechat.com/EN0Oxi2mOaOGe16jZzil2zU"); //alert(the_text); $('#qrcodeid').qrcode({ width:140, height:140, render:"canvas", //設定渲染方式 table canvas typeNumber : -1, //計算模式 correctLevel : 0,//糾錯等級 background :
"#fff",//背景顏色 foreground : "#000",//前景顏色 text:the_text }); }); 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; }