index.html 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">
  3. <head>
  4. <title>Javascript 二维码生成库:QRCode</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
  7. <script type="text/javascript" src="http://static.runoob.com/assets/jquery/2.0.3/jquery.min.js"></script>
  8. <script type="text/javascript" src="http://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
  9. </head>
  10. <body>
  11. <input id="text" type="text" value="http://www.runoob.com" style="width:80%" /><br />
  12. <div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>
  13. <script type="text/javascript">
  14. var qrcode = new QRCode(document.getElementById("qrcode"), {
  15. width : 100,
  16. height : 100
  17. });
  18. function makeCode () {
  19. var elText = document.getElementById("text");
  20. if (!elText.value) {
  21. alert("Input a text");
  22. elText.focus();
  23. return;
  24. }
  25. qrcode.makeCode(elText.value);
  26. }
  27. makeCode();
  28. $("#text").
  29. on("blur", function () {
  30. makeCode();
  31. }).
  32. on("keydown", function (e) {
  33. if (e.keyCode == 13) {
  34. makeCode();
  35. }
  36. });
  37. </script>
  38. </body>
  39. </html>