qrcode網頁生成二維碼

jquery.qrcode.js

http://blog.jetienne.com/blog/2011/04/07/jquery-qrcode/javascript

介紹:java

jquery.qrcode.js is jquery plugin for a pure browser qrcode generation. It allow you to easily add qrcode to your webpages.jquery

使用:git

How to Use It

Let me walk you thru it. First include it in your webpage with the usual script taggithub

<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 divweb

<div id="qrcode"></div>

Then you add the qrcode in this container bycanvas

jquery('#qrcode').qrcode("this plugin is great");

詳細使用:this

$("#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"
});code

要支持中文,需轉碼:blog

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

相關文章
相關標籤/搜索