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

Source: Internet
Author: User

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

Try it?

Resources download

QRCode Library and example download:qrcodejs-04f46c6.zip

Github Address:Https://github.com/davidshimjs/qrcodejs

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

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.