Qrcode.js: Using JavaScript to generate two-dimensional code

Source: Internet
Author: User

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"Xml:lang= "Ko"Lang= "Ko"><Head><title>Javascript QR code generation Library: QRCode</title><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><Metaname= "Viewport"content= "Width=device-width,initial-scale=1,user-scalable=no" /><Scripttype= "Text/javascript"src= "Http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></Script><Scripttype= "Text/javascript"src= "Http://static.runoob.com/assets/qrcode/qrcode.min.js"></Script></Head><Body><inputID= "text"type= "text"value= "Http://www.runoob.com"style= "width:80%" /><BR/><DivID= "QRCode"style= "width:100px; height:100px; margin-top:15px;"></Div><Scripttype= "Text/javascript">varQRCode= NewQRCode (document.getElementById ("QRCode"), {width: -, Height: -});functionMakecode () {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></HTML>

View Online Sample: Http://www.runoob.com/try/try.php?filename=tryhtml5_QRCode

What is Qrcode.js?

Qrcode.js is a JavaScript library for generating two-dimensional code. This is done primarily by getting the tags of the DOM and then drawing from the HTML5 Canvas, without relying on any libraries.

Basic usage
<div id = "QRCode" ></div><script type= "text /javascript ">new  Qrcode (document. Getelementbyid "QRCode"  "http://www.runoob.com" );  //set the link to generate the QR code </SCRIPT>   

Or use some optional parameter settings:

VarQRCode= New QRCode("Test", { Text:  "http://www.runoob.com" , Width: 128 , Height: 128 , Colordark :  "#000000" , Colorlight :  "#ffffff ", Correctlevel :  Qrcode. Correctlevel. H               

We can also use the following methods:

QRCode.  Clear();  Clear the Code qrcode.  Makecode("http://www.w3cschool.cc");  Generate another two-dimensional code          
Browser support

Browsers that support this library are: ie6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows mobile, etc.

Instance Code HTML code
<inputid="text"type="text"value="http://www.runoob.com"/> <br/><divid="QRCode"></div>     
CSS Code
#qrcode {width:160px; height:160px; margin-top:15px;} 
JavaScript Code
VarQRCode= New QRCode("QRCode");functionMakecode() { 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 (, function  (e { if  (e. KeyCode == 13)  { Makecode (); }});           

Qrcode.js: Using JavaScript to generate two-dimensional code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.