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方式
//                width: 200, //宽度
//                height: 200, //高度
//                text: "www.codesky.net" //任意内容
//            });
 
 
        //        });
        function generateQRCode(rendermethod, picwidth, picheight, url) {
 
            $("#qrcode").qrcode({
                render: rendermethod, //rendermethod, 渲染方式有table方式(IE兼容)和canvas方式
                width: 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;
            width: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

posted @ 2016-03-31 16:58  Pavilion  阅读(310)  评论(0编辑  收藏  举报