https://www.runoob.com/w3cnote/javascript-qrcodejs-library.html
What is QRCode.js?
QRCode.js is a two-dimensional code used to generate the JavaScript library. Mainly through the acquisition of DOM tab, then formed by drawing HTML5 Canvas, it does not depend on any library.
Basic Usage
<div ID = "qrcode" > </ div> <Script type = "text / JavaScript" > new new QRCode ( Document . the getElementById ( "qrcode" ), "http://www.runoob.com" ); // Set to generate two-dimensional code link </ script>
Or use some optional parameters:
var qrcode = new QRCode("test", { text: "http://www.runoob.com", width: 128, height: 128, colorDark : "#000000", colorLight : "#ffffff", correctLevel : QRCode.CorrectLevel.H });
Similarly, we can use the following methods:
qrcode . Clear (); // Clear the code qrcode . makeCode ( "http://www.w3cschool.cc" ); // generates another two-dimensional code
Browser support
The library supports browsers: IE6 ~ 10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile, and so on.
The example code
HTML code
<input id="text" type="text" value="http://www.runoob.com" /><br /> <div id="qrcode"></div>
CSS code
#qrcode {
width:160px; height:160px; margin-top:15px; }
JavaScript code
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(); } });
Download
Qrcode library and examples Download: qrcodejs-04f46c6.zip
Github Address: https://github.com/davidshimjs/qrcodejs