QRCode.js 生成二維碼

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

使用方法spa

1、載入 JavaScript 文件插件

<script src="qrcode.js"></script>

2、DOM 結構code

<div id="qrcode"></div>

3、調用blog

 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.H
12 });
13 
14 // 使用 API
15 qrcode.clear();
16 qrcode.makeCode('new content');

參數說明接口

new QRCode(element, option)

名稱 默認值 說明
element - 顯示二維碼的元素或該元素的 ID
option   參數配置

 

option 參數說明

 

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

QRCode.CorrectLevel.L圖片

QRCode.CorrectLevel.Mip

QRCode.CorrectLevel.Qelement

QRCode.CorrectLevel.Hget

 

API 接口

 

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