zoukankan      html  css  js  c++  java
  • qrcode插件生成二维码

    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>EmpIndex</title>
        <link href="~/Content/bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet" />
        <script src="~/jquery类库/jquery-3.1.1.js"></script>
        <script src="~/jquery类库/jquery.qrcode.min.js"></script>
    </head>
    <body>
        <table>
            <tr>
                <td>请输入文字内容:</td>
                <td>
                    <input id="txtCount" type="text" />
                </td>
                <td>
                    <input id="Button1" type="button" value="生成" onclick="save()" />
                </td>
            </tr>
        </table>
        <div id="code"></div>
    </body>
    </html>
    <script>
        //如果内容中有中文,在生成二维码钱就要把字符串转换成utf-8  
        function toUtf8(str) {
            var out, i, len, c;
            out = "";
            len = str.length;
            for (i = 0; i < len; i++) {
                c = str.charCodeAt(i);
                if ((c >= 0x0001) && (c <= 0x007F)) {
                    out += str.charAt(i);
                } else if (c > 0x07FF) {
                    out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                    out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                } else {
                    out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                }
            }
            return out;
        }
        function save() {
            var txt = $("#txtCount").val();
            //就目前 微信/支付宝等 不识别其他颜色的二维码  
            $('#code').qrcode({
                text: toUtf8(txt),
                 150,
                height: 150,
                background: '#f00',
                foreground: '#0f0'
            });  
        }
        
    </script>
  • 相关阅读:
    Databases Questions & Answers
    SQL语句
    常见的数据库基础面试题大全
    关于GET POST
    经常遇到的浏览器兼容性问题
    关于JavaScript中apply与call的用法意义及区别(转)
    js闭包的用途
    深入理解js闭包
    undefined与null的区别
    HeapSort快速排序
  • 原文地址:https://www.cnblogs.com/dujian123/p/10564572.html
Copyright © 2011-2022 走看看