jquery-qrcode生成二维码

一、jquery-qrcode

  jquery-qrcode是一个为浏览器生成二维码的jquery插件。我们很容易将它集成到我们的应用。该插件也可以独立使用,也比较小。它是直接在客户端生成二维码生成。所以不会有图片的下载过程,一定程度上提高了系统性能。

二、实例

  1、jquery-qrcode下载地址为:https://github.com/dnspod/jquery-qrcode 。该包解压后有如下几个文件

  2、开始编写程序

    a、创建index.html文件,文件内容如下:

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4 <title>basic example</title>
 5 </head>
 6 <body>
 7 <script src="jquery-1.10.2.min.js"></script>
 8  <script type="text/javascript" src="./src/jquery.qrcode.js"></script>
 9 <script type="text/javascript" src="./src/qrcode.js"></script>
10 <p>Render in table</p>
11 <div id="qrcodeTable"></div>
12 <p>Render in canvas</p>
13 <div id="qrcodeCanvas"></div>
14 <script> 
15     jQuery('#qrcodeTable').qrcode({
16         render    : "table",                <!--二维码生成方式 -->
17         text    : "http://www.baidu.com"  <!-- 二维码内容  -->
18     });    
19     jQuery('#qrcodeCanvas').qrcode({
20         text    : "http://www.baidu.com"
21     });    
22 </script>
23 </body>
24 </html>

 

  由于该插件使用到了jquery,所以我们需要引入jquery的支持。生成的二维码也有两种方式,一种是使用网页table生成网页。另外一种是直接使用canvas生成图片。

 

posted on 2014-06-28 11:42  烟火_  阅读(1675)  评论(0编辑  收藏  举报

导航