jquery-qrcode生成二维码

时间:2023-03-09 01:41:20
jquery-qrcode生成二维码

一、jquery-qrcode

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

二、实例

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

jquery-qrcode生成二维码

  2、开始编写程序

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

 <!DOCTYPE html>
<html>
<head>
<title>basic example</title>
</head>
<body>
<script src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="./src/jquery.qrcode.js"></script>
<script type="text/javascript" src="./src/qrcode.js"></script>
<p>Render in table</p>
<div id="qrcodeTable"></div>
<p>Render in canvas</p>
<div id="qrcodeCanvas"></div>
<script>
jQuery('#qrcodeTable').qrcode({
render : "table", <!--二维码生成方式 -->
text : "http://www.baidu.com" <!-- 二维码内容 -->
});
jQuery('#qrcodeCanvas').qrcode({
text : "http://www.baidu.com"
});
</script>
</body>
</html>

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