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;
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!