欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于jquery二維碼生成插件qrcode

 更新時間:2017年01月07日 10:49:03   作者:好學(xué)的菜鳥  
這篇文章主要為大家詳細介紹了基于jquery二維碼生成插件qrcode的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文將介紹一款基于jquery的二維碼生成插件qrcode,在頁面中調(diào)用該插件就能生成對應(yīng)的二維碼。

 1、首先在頁面中加入jquery庫文件和qrcode插件。

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

2、在頁面布局中添加一個div

<div class="modal-body" id="qrCode" style="left:40px">
 
 </div>

3、調(diào)用qrcode插件。

var str = "http://" + location.host + "/ActivityDetail.html?id=" + row.ActivityGuid + "&isMail=" + row.isMail + "";
$("#qrCode").empty();
 
$('#qrCode').qrcode(str);
 
//$('#qrCode').qrcode("http://www.dbjr.com.cn");//任意字符串

4、我們試驗的時候發(fā)現(xiàn)不能識別中文內(nèi)容的二維碼,通過查找多方資料了解到,jquery-qrcode是采用charCodeAt()方式進行編碼轉(zhuǎn)換的。而這個方法默認(rèn)會獲取它的Unicode編碼,如果有中文內(nèi)容,在生成二維碼前就要把字符串轉(zhuǎn)換成UTF-8,然后再生成二維碼。您可以通過以下函數(shù)來轉(zhuǎn)換中文字符串:

function toUtf8(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;  
}

可以把這個方法直接寫入到引用的插件里面,后面直接調(diào)用即可。如下:

var str = toUtf8("2017雞年大吉!");
$('#qrCode').qrcode(str);

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論