QRCode.js ;是一个用于生成二维码图片的插件。
github地址
在线实例
; ;实例预览 基础示例
实例预览 API ;接口
使用方法
; ;载入 ;JavaScript ;文件
;- <script src="qrcode.js"></script>
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
DOM ;结构
;- <div id="qrcode"></div>
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
调用
;- // 简单方式
- new QRCode(document.getElementById('qrcode'), 'your content');
- // 设置参数方式
- var qrcode = new QRCode('qrcode', {
- text: 'your content',
- width: 256,
- height: 256,
- colorDark : '#000000',
- colorLight : '#ffffff',
- correctLevel : QRCode.CorrectLevel.H
- });
- // 使用 API
- qrcode.clear();
- qrcode.makeCode('new content');
<span ;class="glyphicon ;glyphicon-copy ;margin-r-2">复制</span>
参数说明
; ;- 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>"#000000"</td> ; ;<td>前景色</td> ; ;</tr> ; ;<tr> ; ;<td>colorLight</td> ; ;<td>"#ffffff"</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> ; ;下载