Loading

QRCode.js 生成二维码

QRCode.js 是一个用于生成二维码图片的插件。

使用方法

一、载入 JavaScript 文件

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

二、DOM 结构

<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.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.M

QRCode.CorrectLevel.Q

QRCode.CorrectLevel.H

 

API 接口

 

名称说明
makeCode(text) 设置二维码内容
clear() 清除二维码。(仅在不支持 Canvas 的浏览器下有效)

 

 

posted @ 2017-08-16 09:29  5572  阅读(137)  评论(0编辑  收藏  举报