jquery-qrcode生成二維碼

qrcode.js 是實現二維碼數據計算的核心類,javascript

jquery.qrcode.js 是把它用jquery方式封裝起來的,用它來實現圖形渲染,其實就是畫圖(支持canvas和table兩種方式)java

方法的參數說明jquery

  1. render   : "canvas",//設置渲染方式  
  2. width       : 256,     //設置寬度  
  3. height      : 256,     //設置高度  
  4. typeNumber  : -1,      //計算模式  
  5. correctLevel    : QRErrorCorrectLevel.H,//糾錯等級  
  6. background      : "#ffffff",//背景顏色  
  7. foreground      : "#000000" //前景顏色  
  8. text     : "https://github.com/jeromeetienne/jquery-qrcode"  //設置二維碼內容 

使用起來比較方便,簡單。git

關於中文的問題解決以下:github

對於須要生成的文本信息進行編碼。canvas

  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;
        }

 
相關文章
相關標籤/搜索