用jquery生成二维码

需要准备的的资源,jquery.min.js,excanvas.compiled.js,jquery.qrcode.min.js

下载链接:https://pan.baidu.com/s/1pKL6Qxl

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
    <title></title>
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="excanvas.compiled.js"></script>
    <script type="text/javascript" src="jquery.qrcode.min.js"></script>
    <script type="text/javascript"> 
    function generateQRCode(rendermethod, picwidth, picheight, url) {


        $("#qrcode").qrcode({ 
// 渲染方式有table方式(IE兼容)和canvas方式
            render: rendermethod, 
//宽度 
            width: picwidth,
//高度 
            height:picheight,
//内容
            text: utf16to8(url), 
            //计算模式
            typeNumber:-1,
//二维码纠错级别
            correctLevel:2,
//背景颜色
            background:"#ffffff",
//二维码颜色
            foreground:"#000000" 


        });
    }
    function init() {
        generateQRCode("table",200, 200, "测试");
        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>


    <style type="text/css">
        #codeico{
            position:fixed;//生成绝对定位的元素,相对于浏览器窗口进行定位。元素的位置通过 "left", "top", "right" 以及 "bottom" 
            z-index:9999999;
            width:30px; 
            height:30px;
            background:url(image/1.png) no-repeat;
        }
    </style>
</head>
<body onLoad="init()">
    <h1>Qrcode</h1>
    <div id="qrcode">
        <div id="codeico"></div>
    </div>


</body>
</html>










  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HaleyLiu123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值