jQuery.qrCode.js实现二维码生成

代码如下:

<!DOCTYPE html>
<html>
<head>
<title>basic example</title>
</head>
<style type="text/css">
	*{margin:0;padding:0;font-family:微软雅黑;}
	#qrcode{border:1px solid #AFAFAF;width:200px;height:200px}
</style>
<body>
<script src="../jQuery/jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../jQuery/jquery.qrcode.js"></script>
<script type="text/javascript" src="../jQuery/qrcode.js"></script>

<p>Render in canvas</p>
<div id="qrcode"></div>
<script>
	//中文乱码,将UTF-16转换为UTF-8,UTF-16长度为2位,UTF-8为3位
	String.prototype.toUTF8=function(){
		var result = ""; //转码后的结果
		for(var i=0,maxLen=this.length;i<maxLen;i++) {
			var t = this.charCodeAt(i);
			if( (t >= 0x0001) && (t <= 0x007F)) {
				result +=  this.charAt(i);
			} else if (t > 0x07FF) {  
				result += String.fromCharCode(0xE0 | ((t >> 12) & 0x0F));  
				result += String.fromCharCode(0x80 | ((t >>  6) & 0x3F));  
				result += String.fromCharCode(0x80 | ((t >>  0) & 0x3F));  
			} else {  
				result += String.fromCharCode(0xC0 | ((t >>  6) & 0x1F));  
				result += String.fromCharCode(0x80 | ((t >>  0) & 0x3F));  
			}  
		}
		return result;
	}
	jQuery('#qrcode').qrcode({
		render : "canvas" , //渲染方式:还可以为table方式
		width : 200,  //生成二维码的宽度
		height : 200, //生成二维码的高度
		typeNumber : -1, //计算方式
		correctLevel : QRErrorCorrectLevel.H,//纠错等级
		background : "#FFFFFF", //背景色
		foreground : "#3399CC", //前景色
		text	: "许增强".toUTF8() //会乱码
	});	
</script>

</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值