總體代碼示例:javascript
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title>二維碼生成</title> <link href="${base}/favicon.ico" rel="icon"> <!--[if lt IE 9]> <script src="js/html5shiv.js"></script> <script src="js/respond.js"></script> <![endif]--> <script src="js/jquery.js"></script> <script src="js/jquery.qrcode.js"></script> <style> </style> <script> $().ready(function() { // 二維碼 $qrcode.qrcode({ width: 300, height: 300, text: "www.20eit.cn" }); }); </script> </head> <body> <div class="container"> <div class="wx-qr-box" id="qrcode" class="qrcode"></div> </div> </body> </html>
總體代碼及案例:php
https://gitee.com/20eit/eit/tree/master/qrcode/html
更多使用案例引用:https://www.runoob.com/w3cnote/javascript-qrcodejs-library.htmlhtml5
QRCode.js 是一個用於生成二維碼的 JavaScript 庫。主要是經過獲取 DOM 的標籤,再經過 HTML5 Canvas 繪製而成,不依賴任何庫。java
<div id="qrcode"></div> <script type="text/javascript"> new QRCode(document.getElementById("qrcode"), "http://www.runoob.com"); // 設置要生成二維碼的連接 </script>
或者使用一些可選參數設置:jquery
var qrcode = new QRCode("test", { text: "http://www.runoob.com", width: 128, height: 128, colorDark : "#000000", colorLight : "#ffffff", correctLevel : QRCode.CorrectLevel.H });
一樣咱們能夠使用如下方法:git
qrcode.clear(); // 清除代碼 qrcode.makeCode("http://www.w3cschool.cc"); // 生成另一個二維碼
支持該庫的瀏覽器有:IE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile, 等。github
<input id="text" type="text" value="http://www.runoob.com" /><br /> <div id="qrcode"></div>
#qrcode { width:160px; height:160px; margin-top:15px; }
var qrcode = new QRCode("qrcode"); function makeCode () { var elText = document.getElementById("text"); if (!elText.value) { alert("Input a text"); elText.focus(); return; } qrcode.makeCode(elText.value); } makeCode(); $("#text"). on("blur", function () { makeCode(); }). on("keydown", function (e) { if (e.keyCode == 13) { makeCode(); } });
嘗試一下 »編程
Qrcode 庫及實例下載:qrcodejs-04f46c6.zip瀏覽器
Github 地址:https://github.com/davidshimjs/qrcodejs