码迷,mamicode.com
首页 > Web开发 > 详细

qrcode网页生成二维码

时间:2015-08-05 12:08:04      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

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

qrcode网页生成二维码

标签:

原文地址:http://www.cnblogs.com/wildorchid/p/4703973.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!