zoukankan      html  css  js  c++  java
  • jquery.qrcode.js生成二维码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="js/jquery.min.js"></script>
        <script src="js/jquery.qrcode.min.js"></script>
        <script>
    //        jQuery(function () {
    //            $("#qrcode").qrcode({
    //                render: "table", //table方式
    //                 200, //宽度
    //                height: 200, //高度
    //                text: "www.codesky.net" //任意内容
    //            });
     
     
            //        });
            function generateQRCode(rendermethod, picwidth, picheight, url) {
     
                $("#qrcode").qrcode({
                    render: rendermethod, //rendermethod, 渲染方式有table方式(IE兼容)和canvas方式
                     picwidth, //宽度 
                    height: picheight, //高度 
                    text: url, //内容 中文utf16to8(url),
                    typeNumber: -1, //计算模式
                    correctLevel: 2, //二维码纠错级别
                    background: "#ffffff", //背景颜色
                    foreground: "#000000"  //二维码颜色
     
                });
            }
            function init() {
                generateQRCode("table", 200, 200, "https://hao.360.cn/");
                var margin = ($("#qrcode").height() - $("#codeico").height()) / 2;
                $("#codeico").css("margin", margin);
            }
            //中文编码格式转换
            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;
            }   
     
        </script>
     
        </script>
        <style type="text/css">
            #codeico{
                position:fixed;
                z-index:9999999;
                30px; 
                height:30px;
                background:url(images/text.png) no-repeat;
            }
        </style>
    </head>
    <body  onload="init()">
        <div id="qrcode">
            <div id="codeico"></div>
        </div>
     
    </body>
    </html>
    下载js地址:http://www.oschina.net/p/jquery-qrcode-js

  • 相关阅读:
    [html]Sublime Text添加插件
    [C#.Net]判断文件是否被占用的两种方法
    C#中隐式运行CMD命令行窗口的方法
    [C#.Net]启动外部程序的几种常用方法汇总
    C# 管理员身份运行程序
    [C#.net]PostMessage与SendMessage的区别
    [C#.net] SendMessage
    由浅入深了解Thrift之客户端连接池化续
    由浅入深了解Thrift之客户端连接池化
    由浅入深了解Thrift之服务模型和序列化机制
  • 原文地址:https://www.cnblogs.com/ft-Pavilion/p/5341788.html
Copyright © 2011-2022 走看看