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

github地址

在线实例

; ;

实例预览 基础示例

实例预览 API ;接口

使用方法

; ;

载入 ;JavaScript ;文件

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

<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>

DOM ;结构

;
  1. &lt;div id=&quot;qrcode&quot;&gt;&lt;/div&gt;
; ;

<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>

调用

;
  1. // 简单方式
  2. new QRCode(document.getElementById('qrcode'), 'your content');
  3. // 设置参数方式
  4. var qrcode = new QRCode('qrcode', {
  5. text: 'your content',
  6. width: 256,
  7. height: 256,
  8. colorDark : '#000000',
  9. colorLight : '#ffffff',
  10. correctLevel : QRCode.CorrectLevel.H
  11. });
  12. // 使用 API
  13. qrcode.clear();
  14. qrcode.makeCode('new content');
; ;

<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>

参数说明

; ;
  1. new QRCode(element, option)
; ;

<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>

; ; ; ; ;<table ;class="table ;table-striped ;table-bordered ;table-condensed"> ; ;<thead> ; ;<tr ;class="firstRow"><th ;width="80">名称</th><th ;width="100">默认值</th><th>说明</th></tr> ; ;</thead> ; ;<tbody> ; ;<tr> ; ;<td>element</td> ; ;<td>-</td> ; ;<td>显示二维码的元素或该元素的 ;ID</td> ; ;</tr> ; ;<tr> ; ;<td>option</td> ; ;<td> </td> ; ;<td>参数配置</td> ; ;</tr> ; ;</tbody> ; ;</table> ; ;

option ;参数说明

; ;

; ;<table ;class="table ;table-striped ;table-bordered ;table-condensed"> ; ;<thead> ; ;<tr ;class="firstRow"><th ;width="80">名称</th><th ;width="180">默认值</th><th>说明</th></tr> ; ;</thead> ; ;<tbody> ; ;<tr> ; ;<td>width</td> ; ;<td>256</td> ; ;<td>图像宽度</td> ; ;</tr> ; ;<tr> ; ;<td>height</td> ; ;<td>256</td> ; ;<td>图像高度</td> ; ;</tr> ; ;<tr> ; ;<td>typeNumber</td> ; ;<td>4</td> ; ;<td> </td> ; ;</tr> ; ;<tr> ; ;<td>colorDark</td> ; ;<td>&quot;#000000&quot;</td> ; ;<td>前景色</td> ; ;</tr> ; ;<tr> ; ;<td>colorLight</td> ; ;<td>&quot;#ffffff&quot;</td> ; ;<td>背景色</td> ; ;</tr> ; ;<tr> ; ;<td>correctLevel</td> ; ;<td>QRCode.CorrectLevel.L</td> ; ;<td>容错级别,可设置为: ; ;

QRCode.CorrectLevel.L

QRCode.CorrectLevel.M

QRCode.CorrectLevel.Q

QRCode.CorrectLevel.H

API ;接口

; ;<table ;class="table ;table-striped ;table-bordered ;table-condensed"> ; ;<thead> ; ;<tr ;class="firstRow"><th ;width="80">名称</th><th>说明</th></tr> ; ;</thead> ; ;<tbody> ; ;<tr> ; ;<td>makeCode(text)</td> ; ;<td>设置二维码内容</td> ; ;</tr> ; ;<tr> ; ;<td>clear()</td> ; ;<td>清除二维码。(仅在不支持 ;Canvas ;的浏览器下有效)</td> ; ;</tr> ; ;</tbody> ; ;</table> ; ;

下载