Qrcode.js
Qrcode.js is dependent on JS to generate two-dimensional code. Mainly by obtaining the tag of the DOM, and then drawn by Html5canvas, not dependent on JQ
Get Qrcode.js
- Github-page:qrcode.js
- There are tar.gz packages and zip packages.
- Github-repository
Introduction and Usage Introduction
- As long as
it is introduced in, JQ is not dependent and can be replaced by other versions of JQ (other content useful to JQ, such as selector acquisition)
<script type="text/javascript" src="qrcode.js"></script>
Basic usageGet the block, call the default method directly (enter the generated string to generate the QR code)
<div id="qrcode"></div><script type="text/javascript"> new QRCode(document.getElementById("qrcode"), "https//blog.csdn.net/crper");</script>
Advanced usageQRCode supports the following parameters:
- Width (wide)
- Height (altitude)
- Colordark (background color)
- Colorlight (front view)
- Correctlevel (fault tolerance level, support L,m,h) Low/middle/high
varnew QRCode("test", { "https//blog.csdn.net/crper", 400, 400, "#000000", "#ffffff", // 清除二维码qrcode.makeCode("http://naver.com"// 生成另外一个二维码
Online generation functionThis function is to get the ID of text, to determine whether the content is empty, the popup window is empty, and not empty to generate a two-dimensional code
function makeCode () { var elText = document.getElementById("text"); if (!elText.value) { alert("请输入您要生成的二维码内容!"); elText.focus(); return; } qrcode.makeCode(elText.value);}makeCode();
Trigger by calling Blur and KeyDown, generate a QR code when you click out of focus, or enter content and press ENTER
$("#text"). on("blur"function () { makeCode(); }). on("keydown"function (e) { if13) { makeCode(); } });
Practical Small Example<! DOCTYPE html><html> <head> <title>Demo</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 " /> <!--referencing local script files -- <script type="text/javascript" src="Jquery.min.js"></script> <script type="text/javascript" src="Qrcode.js"> </script> <style> #qrcode { height: + px; width: px; background: #eee; } input { height: px; line-height: px; width: px; } </style> </head> <body> <input id="text" type="text" value="This is a test text, After clearing, enter the content you want to generate " /> <div id="QRCode"></div> <!--script is to be put in the back .......--> <script type="Text/javascript"> varQRCode =NewQRCode (document.getElementById ("QRCode"), {width: -, Height: -, Colordark:"#000000", Colorlight:"#03f594", CORRECTLEVEL:QRCODE.CORRECTLEVEL.L}); function makecode() { varEltext = 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 = = -) {Makecode (); } });</script> </body>
Browser adaptation to support the following
PC |
Mobile |
Ie6~10 |
Mobile Safari |
Chrome |
Android |
Firefox |
Windows Mobile |
Safari |
|
Opera |
|
Follow the agreementMIT License
Qrcodejs generate two-dimensional code