星空网 > 软件开发 > Java

jQuery qrcode生成二维码

qrcode.js 是实现二维码计算的核心类

jQuery.qrcode.js 把它用jQuery封装起来,用来实现图像渲染 也就是画图。支持table和canvas

所需环境:jQuery.min.js压缩文件(或jQuery.js)

     jQuery.qrcode.min.js压缩文件(或 jQuery.qrcode.js  qrcode.js源文件)

     utf16to8.js。因为qrcode不支持中文,所以需要将Unicode编码转出utf-8编码,不涉及中文就不用该方法。

 

生成二维码代码:

  $("#qrcodeCanvas).qrcode({render:"canvas",width:256,height:256,text:"https://www.baidu.com"});  若是中文:text:utf16to8("王小小")

 

utf16to8.js代码

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




原标题:jQuery qrcode生成二维码

关键词:jquery

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流