jq + qrcode 生成二维码(解决中文乱码)

来源:互联网 发布:玩转linux 编辑:程序博客网 时间:2024/03/29 01:00
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>生成二维码</title><script type='text/javascript' src='http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js'></script><script type="text/javascript" src="http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js"></script></head><body><div id="qrcode"></div><script>var str= "阿斯达四大四大1|9131000xxx90X2|中国(上海)自阿斯达四大四大号302部位368室|021-583xx909|中信银行股份有限公司上海长宁支行|731ssssss00061061";//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;  }   $('#qrcode').qrcode({width: 164,height: 164,text: utf16to8(str)});      </script></body></html>

原创粉丝点击