QRCode.js 生成二維碼

QRCode.js 是一個用於生成二維碼圖片的插件。git

在線實例

實例預覽 基礎示例api

實例預覽 API 接口瀏覽器

使用方法

載入 JavaScript 文件

  1. <script src="qrcode.js"></script>
複製

DOM 結構

  1. <div id="qrcode"></div>
複製

調用

  1. // 簡單方式 
  2. new QRCode(document.getElementById('qrcode'), 'your content'); 
  3.  
  4. // 設置參數方式 
  5. var qrcode = new QRCode('qrcode', { 
  6.   text: 'your content', 
  7.   width: 256, 
  8.   height: 256, 
  9.   colorDark : '#000000', 
  10.   colorLight : '#ffffff', 
  11.   correctLevel : QRCode.CorrectLevel.
  12. }); 
  13.  
  14. // 使用 API 
  15. qrcode.clear(); 
  16. qrcode.makeCode('new content'); 
複製

參數說明

  1. new QRCode(element, option)
複製
   
名稱 默認值 說明
element - 顯示二維碼的元素或該元素的 ID
option   參數配置

option 參數說明

名稱 默認值 說明
width 256 圖像寬度
height 256 圖像高度
typeNumber 4  
colorDark "#000000" 前景色
colorLight "#ffffff" 背景色
correctLevel QRCode.CorrectLevel.L 容錯級別,可設置爲:

QRCode.CorrectLevel.Lspa

QRCode.CorrectLevel.M插件

QRCode.CorrectLevel.Qcode

QRCode.CorrectLevel.H接口

API 接口

名稱 說明
makeCode(text) 設置二維碼內容
clear() 清除二維碼。(僅在不支持 Canvas 的瀏覽器下有效)
相關文章
相關標籤/搜索