What should you do when you need a QR code with the content you want to represent or the web page you want to enter?
Today, let's look at the generation of a random QR Code:
Tools used:
Microsoft Visual Studio 2010
SQL Server Management Studio
First, we have to introduce two libraries:
<script type="text/javascript" src="http://static.runoob.com/assets/jquery/2.0.3/jquery.min.js"></script> <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
Then we have to introduce a control:
<asp:DropDownList ID="DropDownList2" runat="server" Height="16px" Width="322px" AutoPostBack="True" onchange="makeCode()" > </asp:DropDownList>
This control is a drop-down list control onchange="makeCode()" the method is to call the following JS method
Next is the JS method of generating QR code
<script type="text/javascript"> var qrcode = new QRCode(document.getElementById("qrcode"), { width: 100, height: 100 }); function makeCode() { var elText = document.getElementById("DropDownList2"); if (!elText.value) { elText.focus(); return; } qrcode.makeCode(elText.value); } makeCode(); $("#text"). on("blur", function () { makeCode(); }). on("keydown", function (e) { if (e.keyCode == 13) { makeCode(); } }); </script>
The DropDownList2 in the database calls the data in the database, and the incoming data is DropDownList2.SelectedValue
If you don't understand the drop-down method, you can use the input box method directly.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko"> <head> <title>Javascript QR code generator: QRCode</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" /> <script type="text/javascript" src="http://static.runoob.com/assets/jquery/2.0.3/jquery.min.js"></script> <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script> </head> <body> <input id="text" type="text" value="http://www.runoob.com" style="width:80%" /><br /> <div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div> <script type="text/javascript"> var qrcode = new QRCode(document.getElementById("qrcode"), { width : 100, height : 100 }); 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(); } }); </script> </body> </html>
It is also necessary to introduce two libraries: jquery.min.js and qrcode.min.js