• jquery-qrcode生成二维码


    1. 引用方式:

    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="http://apps.bdimg.com/libs/jquery-qrcode/1.0.0/jquery.qrcode.min.js"></script>

    2. 使用方式:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1,user-scalable=no">
            <meta name="format-detection" content="telephone=no">
            <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
            <script src="http://apps.bdimg.com/libs/jquery-qrcode/1.0.0/jquery.qrcode.min.js"></script>
            <title></title>
        </head>
    
        <body>
            <div id="qrcode"></div>
            <script type="text/javascript">
                $('#qrcode').qrcode({
                    render: "canvas",     //默认配置,可以为空也可以替换为table
                     "250",        //设置宽度
                    height: "250",      //设置高度
                    foreground: "#C00",    //二维码颜色
                     background: "#FFF",    //背景色
                    text: 'https://www.cnblogs.com/xyyt', //二维码内容            
                });
            </script>
        </body>
    </html>

    3. 微信中识别二维码——转换为图片格式:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1,user-scalable=no">
            <meta name="format-detection" content="telephone=no">
            <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
            <script src="http://apps.bdimg.com/libs/jquery-qrcode/1.0.0/jquery.qrcode.min.js"></script>
            <title></title>
        </head>
        <body>
            <div id="qrcode"></div>
            <img id="qrcodeImg"/>
            <script type="text/javascript">
                var qrcode = $('#qrcode').qrcode({
                    render: "canvas",     //默认配置,可以为空也可以替换为table
                     "250",        //设置宽度
                    height: "250",      //设置高度
                    foreground: "#C00",    //二维码颜色
                     background: "#FFF",    //背景色
                    text: 'https://www.cnblogs.com/xyyt', //二维码内容            
                }).hide();
                //将生成的二维码转换成图片格式
                var canvas = qrcode.find('canvas').get(0);
                $('#qrcodeImg').attr('src', canvas.toDataURL('image/jpg'));
            </script>
        </body>
    </html>

    4. 生成中文:

            <div id="chinese_qrcode"></div>
            <script>
                $(function() {
                    function utf16to8(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;
                    }
                    jQuery("#chinese_qrcode").qrcode(utf16to8("中文中文")); //使用encodeURI进行转码
                })
            </script>
  • 相关阅读:
    python的字符串连接操作符+
    python-在定义函数时,不定长参数中,默认值参数不能放在必选参数前面
    python中的sort方法使用详解
    详解Python中的join()函数的用法
    python中map()函数
    python的匿名函数lambda解释及用法
    python 代码的缩进位置决定执行部分
    python代码位置引发的错误
    python中如何使输出不换行
    git stash
  • 原文地址:https://www.cnblogs.com/xyyt/p/9408991.html
Copyright © 2020-2023  润新知