JavaScript 通过 jquery.qrcode 生成二维码 亲测

JavaScript 通过jquery.qrcode生成二维码

通过jquery.qrcode生成二维码


<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Qrcode</title>

  <!-- https://code.jquery.com/ -->
  <script type="text/javascript" src="./jquery-1.12.4.min.js"></script>
  <!-- https://github.com/jeromeetienne/jquery-qrcode -->
  <script type="text/javascript" src="./jquery.qrcode.min.js"></script>

 </head>
 <body>

  <div id="qrcode1"></div>
  <div id="qrcode2"></div>
  <div id="qrcode3"></div>

  <script type="text/javascript">
  
	/**
    * 生成二维码
    */
	$('#qrcode1').qrcode("https://blog.csdn.net/qcl108");

	/**
    * 生成二维码
    * width: 宽度
    * height: 高度
    */
	$('#qrcode2').qrcode(
		{
			width: 120,
			height: 120,
			text: "size doesn't matter"
		}
	);

	/**
	* 内容包含中文需要先转换
	*/
	function toUtf8(str) {
		var res = '', len = str.length;
		for(var i = 0; i < len; i++) {
			var c = str.charCodeAt(i);
			if ((c >= 0x0001) && (c <= 0x007F)){
				res += str.charAt(i);
			} else if (c > 0x07FF) {
				res += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
				res += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
				res += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
			} else{
				res += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
				res += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
			}
		}

		return res;
	}
	
	/**
    * 生成内容包含中文的二维码
    */
	$('#qrcode3').qrcode(
		{
			width: 120,
			height: 120,
			text: toUtf8("生成二维码 https://blog.csdn.net/qcl108")
		}
	);
  </script>
 </body>
</html>

在这里插入图片描述

如果您觉得有帮助,欢迎点赞哦 ~ 谢谢!!

  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值