Jquery插件-jquery-qrcode生成二維碼

現在jquery.min.js和jquery.qrcode.min.js文件

先將js文件引入

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.qrcode.min.js"></script>

將要顯示二維碼的地方添加一下代碼:

<div id="qrcode"></div>
在文檔尾引入設置代碼:

<script type="text/javascript">
jQuery('#qrcode').qrcode({
	width: 100,
  	height: 100,
  	render: "canvas", //設置渲染方式 table canvas
  	text: utf16to8("javascript生成二維碼"),
  	background: "#ffffff", //背景顏色 
  	foreground: "red" //前景顏色 F
	});

//轉碼
	 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;
	 } 
</script>




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章