canvas教程

jQuery qrcode生成二维码

字号+ 作者:H5之家 来源:H5之家 2016-09-29 13:00 我要评论( )

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

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 8个能够有效帮助你提高jQuery代码性能(performance)的技巧

    8个能够有效帮助你提高jQuery代码性能(performance)的技巧

    2016-09-04 10:00

  • jQuery meets the HTML5 canvas

    jQuery meets the HTML5 canvas

    2016-08-28 16:00

  • 简介 jCanvas:当 jQuery遇上HTML5 Canvas

    简介 jCanvas:当 jQuery遇上HTML5 Canvas

    2016-08-22 12:01

  • 10个帮助你创建超棒jQuery插件的小技巧

    10个帮助你创建超棒jQuery插件的小技巧

    2016-06-11 10:00

网友点评
s