jquery.qrcode.js
http://blog.jetienne.com/blog/2011/04/07/jquery-qrcode/
介绍:
jquery.qrcode.js is jquery plugin for a pure browser qrcode generation. It allow you to easily add qrcode to your webpages.
使用:
How to Use It
Let me walk you thru it. First include it in your webpage with the usual script tag
<script type="text/javascript" src="jquery.qrcode.min.js"></script>
Then create a DOM element which gonna contains the generated qrcode image. Lets say a div
<div id="qrcode"></div>
Then you add the qrcode in this container by
jquery(‘#qrcode‘).qrcode("this plugin is great");
详细使用:
$("#code").qrcode({
render: "canvas", //table方式
width: 200, //宽度
height:200, //高度
typeNumber: -1, //计算模式
//correctLevel: QRErrorCorrectLevel.H,//纠错等级
background: "#ffffff",//背景颜色
foreground: "#000000", //前景颜色
// text: utf16to8("钓鱼岛是中国的!") //任意内容
text:"http://www.baidu.com"
});
要支持中文,需转码:
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;
}
下载:
https://github.com/jeromeetienne/jquery-qrcode