jquery realizes micro-letter long by recognizing two-dimensional code function _jquery

Source: Internet
Author: User

Recently has been engaged in a micro-letter development project, is finally nearing completion, today, small editing a time record in the project development process encountered jquery.qrcode.min.js generation of two-dimensional code length according to the unrecognized solution, I hope to help!

1. Introduction of JS Library

<script src= "Jquery-1.8.3.js" type= "Text/javascript" charset= "Utf-8" ></script> <script "src=" 
Jquery.qrcode.min.js "type=" Text/javascript "charset=" Utf-8 "></script>

2. Create an empty div on the page;

<div id= "Qrdiv" ></div>

3. Generate two dimensional code

$ ("#qrDiv"). QRCode ({ 
width:120,//Width 
height:120,//height 
text: "Need to generate two-dimensional code content"/arbitrary content 
});

Note: This time the generated two-dimensional code in the micro-letter Changan did not respond, because qrcode generated by the canvas tag rather than the IMG tag

4. Convert the canvas label to an IMG tag

Extract picture image 
function convertcanvastoimage (canvas) { 
//New Image object from canvas, which can be understood as Dom 
var image = new Image (); c4/>//Canvas.todataurl Returns a string of BASE64 encoded URLs, of course, the browser itself definitely supports 
//Specifies the format PNG 
image.src = Canvas.todataurl ("Image/png" ); 
return image; 
} 
Gets the canvas object in the Web page 
var mycanvas1=document.getelementsbytagname (' canvas ') [0]; 
Inserts the converted IMG tag into the HTML 
var img=convertcanvastoimage (MYCANVAS1); 
$ (' #imagQrDiv '). Append (img);//imagqrdiv indicates the container ID you want to insert

Note: After completing the above steps, it can be identified in the micro-letter long

The above is a small set to introduce jquery to realize the micro-letter long according to identify two-dimensional code function, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.