JS call to generate two-dimensional code

Source: Internet
Author: User
Tags 0xc0

has been used in the Java background call Qrcode.jar form to produce two-dimensional code, and then the web foreground display of the form of the two-dimensional code, and then feel that if you can call the JS framework to produce two-dimensional code will be better soon. At least you can reduce the number of interactions with the browser and reduce the pressure in the background.

Search some information after feeling no one can be used, at least the compatibility of IE browser is still a problem, through their own debugging wrote a demo. Hope to help everyone, save time for everyone

The specific demo can be downloaded via http://download.csdn.net/detail/fugui6611634/7337467.

will be a string (can be Chinese, in the generation of two-dimensional code image before the Chinese transcoding) to generate a two-dimensional code picture, if you want to take log of the QR code, you can create a second-dimensional code in the middle part of their own to add a small log,log picture not too big, otherwise it will not be scanned content.

[HTML] View Plaincopyprint?
  1. <title></title>
  2. <script src= "Js/jquery-1.8.3.js" type= "Text/javascript" ></script>
  3. <script src= "Js/jquery.qrcode.min.js" type= "Text/javascript" ></script>
  4. <script type= "Text/javascript" >
  5. $ (function () {
  6. $ ("#bt"). Bind ("click", Function () {
  7. Text = $ ("#text"). Val ();
  8. $ ("#div_div"). QRCode (Utf16to8 (text));
  9. })
  10. })
  11. function Utf16to8 (str) {//transcoding
  12. var out, I, Len, C;
  13. out = "";
  14. len = str.length;
  15. for (i = 0; i < len; i++) {
  16. c = str.charcodeat (i);
  17. if ((c >= 0x0001) && (c <= 0x007F)) {
  18. Out + = Str.charat (i);
  19. } else if (C > 0x07ff) {
  20. Out + = String.fromCharCode (0xE0 | ((c >> b) & 0x0F));
  21. Out + = String.fromCharCode (0x80 | ((c >> 6) & 0x3F));
  22. Out + = String.fromCharCode (0x80 | ((c >> 0) & 0x3F));
  23. } else {
  24. Out + = String.fromCharCode (0xC0 | ((c >> 6) & 0x1F));
  25. Out + = String.fromCharCode (0x80 | ((c >> 0) & 0x3F));
  26. }
  27. }
  28. return out;
  29. }
  30. </script>
  31. <body>
  32. <input type= "text" id= "text"/>
  33. <input type= "button" value= "SHENGC" id= "BT"/>
  34. <div id= "Div_div" style= "width:400px;height:400px;border:1px solid #000;" ></div>
  35. </body>
 
   
  
  1. JQuery (' #output '). QRCode ({width:200,height:200,correctlevel:0,text:content});
  2. For specific parameter descriptions see the following
  1. Render : "Canvas|table",//Set Rendering mode
  2. Width : Up to, //Set Wide
  3. Height : Up to, //set altitude
  4. Typenumber :-1, //Calculation mode
  5. Correctlevel : qrerrorcorrectlevel.h,//error correction level
  6. Background : "#ffffff",//Background color
  7. Foreground

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.