QRCode.js 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
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(); } });