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>
  • 相关阅读:
    Lua小技巧
    Lua中使用table实现的其它5种数据结构
    Lua 5.3 协程简单示例
    Lua 5.3 迭代器的简单示例
    Lua函数以及闭合函数的理解
    BabeLua常见问题
    Windows下的lua-5.3.4安装过程
    C++ 设计模式 开放封闭原则 简单示例
    UML基础系列:类图
    面向对象程序设计基本概念
  • 原文地址:https://www.cnblogs.com/dujian123/p/10564572.html
Copyright © 2011-2022 走看看