jQuery生成二维码

来源:互联网 发布:有没有像淘宝联盟一样 编辑:程序博客网 时间:2024/05/20 02:28

jQuery.qrcode

实例下载

jQuery生成二维码实例下载

  1. <html>

  2.  <head>

  3.  <script type="text/javascript" src="jquery-1.3.2.min.js"></script>

  4.  <script type="text/javascript" src="jquery.qrcode-0.12.0.min.js"></script>

  5.    <script type="text/javascript">

  6.    

  7.     $(function(){

  8.      $("#bcTarget").barcode("123456789", "codabar",{barWidth:2, barHeight:80});

  9.      //二维码

  10.      $("#two").qrcode({

  11.    "render": "div",

  12.    "size": 100,

  13.    "color": "#3a3",

  14.    "text": "http://liubo.club"

  15.      });

  16. });

  17.  

  18.    </script>

  19.  </head>

  20.  <body>

  21. 二维码

  22. <br>

  23. <div id="two"></div>

  24. </body>

  25. </html>





  1. <html>
  2.  <head>
  3.    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
  4.    <script type="text/javascript" src="jquery-barcode-2.0.1.js"></script>
  5. <script type="text/javascript" src="jquery.qrcode-0.12.0.min.js"></script>
  6.    <script type="text/javascript">
  7. //中文问题
  8.    function toUtf8(str) {      
  9.    var out, i, len, c;      
  10.    out = "";      
  11.    len = str.length;      
  12.    for(i = 0; i < len; i++) {      
  13.        c = str.charCodeAt(i);      
  14.        if ((c >= 0x0001) && (c <= 0x007F)) {      
  15.            out += str.charAt(i);      
  16.        } else if (c > 0x07FF) {      
  17.            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));      
  18.            out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));      
  19.            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));      
  20.        } else {      
  21.            out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));      
  22.            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));      
  23.        }      
  24.    }      
  25.    return out;      
  26. }  
  27.     $(function(){
  28.      $("#bcTarget").barcode("123456789", "codabar",{barWidth:2, barHeight:80});
  29.      //二维码
  30.      $("#two").qrcode({
  31.    "render": "div",
  32.    "size": 100,
  33.    "color": "#3a3",
  34.    "text": "http://liubo.club"
  35.      });
  36.      //生成条形码
  37.      $("#genid").click(function(){
  38.      var code = $("#orgcode").val();
  39.      $("#mycode").barcode(code, "codabar",{barWidth:2, barHeight:80});
  40.      });
  41.      //生成二维码
  42.       $("#twobtn").click(function(){
  43.      var qrcode = $("#twotext").val();
  44.      qrcode =toUtf8(qrcode);
  45.      $("#twoimg").qrcode({
  46.    "render": "div",
  47.    "size": 100,
  48.    "color": "#3a3",
  49.    "text": qrcode
  50.      });
  51.      });
  52. });
  53.  
  54.    </script>
  55.  </head>
  56.  <body>
  57. 首先自动生成条形码 123456789
  58. <div id="bcTarget"></div>
  59. 输入要生成条形码的数字
  60. <input type="text" id ="orgcode">
  61. <div id="mycode"> </div>
  62. <input type="button"  value="生成条形码" id="genid"/>
  63. <br>
  64. <p>
  65. liubo.club 二维码
  66. <br>
  67. <div id="two"></div>
  68. <p>
  69. 输入内容生成二维码
  70. <input type="text" id="twotext"/>
  71. <br>
  72. <input type="button" value="生成二维码" id="twobtn"/>
  73. <div id="twoimg"> </div>
  74. </body>
  75. </html>


关于生成的选项


Usage

The syntax is very simple. Just use

$(selector).qrcode(options);

to append a new generated HTML element representing the QR code to the selected elements. If the selected element already is a canvas element, then the QR code is drawn onto it.

Options

The available options and their default values are:

{    // render method: 'canvas', 'image' or 'div'    render: 'canvas',    // version range somewhere in 1 .. 40    minVersion: 1,    maxVersion: 40,    // error correction level: 'L', 'M', 'Q' or 'H'    ecLevel: 'L',    // offset in pixel if drawn onto existing canvas    left: 0,    top: 0,    // size in pixel    size: 200,    // code color or image element    fill: '#000',    // background color or image element, null for transparent background    background: null,    // content    text: 'no text',    // corner radius relative to module width: 0.0 .. 0.5    radius: 0,    // quiet zone in modules    quiet: 0,    // modes    // 0: normal    // 1: label strip    // 2: label box    // 3: image strip    // 4: image box    mode: 0,    mSize: 0.1,    mPosX: 0.5,    mPosY: 0.5,    label: 'no label',    fontname: 'sans',    fontcolor: '#000',    image: null}





0 0
原创粉丝点击