zoukankan      html  css  js  c++  java
  • jquery.qrcode笔记

    由于一个坑爹的项目需要生成二维码扫描,后台由于数据库比较麻烦,就只能前端做了,于是乎找到Js生成qrcode的一个库:https://github.com/jeromeetienne/jquery-qrcode,试用了下感觉挺方便的,做个记录。

    这是Jquery的一个插件,需要用到Jquery。

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>QRCODE TEST</title>
     6 </head>
     7 <body>
     8     <div id="code"></div>
     9 </body>
    10 <script src="./jquery/jquery.js"></script>
    11 <script src="./jquery/jquery.qrcode.min.js"></script>
    12 <script>
    13     function changeToUtf8(str) {    
    14     var output, i, len, c;    
    15     output = "";    
    16     len = str.length;    
    17     for(i = 0; i < len; i++) {    
    18         c = str.charCodeAt(i);    
    19         if ((c >= 0x0001) && (c <= 0x007F)) {    
    20             output += str.charAt(i);    
    21         } else if (c > 0x07FF) {    
    22             output += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));    
    23             output += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));    
    24             output += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    
    25         } else {    
    26             output += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));    
    27             output += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    
    28         }    
    29     }    
    30     return output;    
    31 } 
    32     var str=changeToUtf8("尼玛");
    33     $("#code").qrcode({
    34         render:"table",
    35         200,
    36         height:200,
    37         text:str
    38     });
    39 </script>
    40 </html>

    之所以需要个changeToUft8函数是因为中文字符直接生成二维码再进行扫描读取的话会乱码,qrcode是采用charCodeAt()进行转码的,默认是unicode编码。

  • 相关阅读:
    配置caffe matlab 中遇到的坑
    VGGnet论文总结(VERY DEEP CONVOLUTIONAL NETWORKS FOR LARGE-SCALE IMAGE RECOGNITION)
    内核笔记
    VM上安装centos6.x & java & tomcat & mysql
    ----
    python 入门笔记
    centos7 安装 mysql & jetty
    VM 中 CentOS 6 的相关配置
    论文 单词句子笔记
    Android 百度地图开发(三)--- 实现比例尺功能和替换自带的缩放组件
  • 原文地址:https://www.cnblogs.com/debugzer0/p/5282494.html
Copyright © 2011-2022 走看看