本篇文章给大家带来的内容是关于js如何生成二维码?js生成二维码的方法(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
在js中生成二维码
一、准备工作
首先需要准备依赖资源
1、jquery.js
2、qrcode (https://github.com/jeromeetienne/jquery-qrcode)
二、引用方式
1 2 3 | html<script type= "text/javascript" src= "jquery.qrcode.min.js" ></script>
或js
require ( "yourPath/jquery-qrcode-master/jquery.qrcode.min" );
|
Salin selepas log masuk
三、页面显示
四、js处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | $('#qrcode').qrcode( "www.baidu.com" );
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;
};
text : "这里放二维码的内容,涉及中文时需要转换为utf8"
render : "canvas" ,
width : 256,
height : 256,
typeNumber : -1,
correctLevel : QRErrorCorrectLevel.H,
background : "#ffffff" ,
foreground : "#000000"
|
Salin selepas log masuk
相关推荐:
javascript如何实现购物车的功能(代码)
原生js实现日历的思路与代码Atas ialah kandungan terperinci js如何生成二维码?js生成二维码的方法(代码). Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!