Qrcodejs generate two-dimensional code

Source: Internet
Author: User

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 usage

Get 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 usage

QRCode 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 function

This 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 agreement

MIT License

Qrcodejs 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.