js 生成二维码 qrcode jq

15 篇文章 0 订阅
1 篇文章 0 订阅
因为部分原因,前端页面需要用到二维码,后台处理起来又比较费事一些,需要前端来进行处理,后台返回一个二维码的链接,前端生成一个二维码

    一定要引入qrcode.min.js
    我自己使用的是哪个版本,忘记了,我新找了一个链接,应该可以直接使用
    
    <script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>

<!DOCTYPE html>
<html lang="en" data-use-rem="750">

<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="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <title>二维码</title>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            background: url("./img/bj.png") no-repeat;
            background-size: 100% 100%;
            overflow: hidden;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }

        .box {
            position: fixed;
            left: 50%;
            top: 72%;
            width: 3.6rem;
            margin-left: -1.8rem;
            overflow: hidden;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }

        .walletAddressImg {
            width: 90px;
            height: 90px;
            background: url("./img/kuang.png") no-repeat;
            background-size: 100% 100%;
            padding: 0.1rem;
            margin: 0 auto;
            -webkit-box-sizing: border-box;
            -moz-box-sizing: border-box;
            box-sizing: border-box;
        }

        .walletAddressImg img {
            margin: 0 auto;
            /*margin-top: 3px;*/
        }

        .code {
            text-align: center;
            width: 3.6rem;
            height: 0.7rem;
            line-height: 0.7rem;
            margin-top: 0.2rem;
            background: url("./img/fuzhi.png") no-repeat;
            background-size: 100% 100%;
        }

        a {
            display: block;
            height: 100%;
            text-decoration: none;
            font-size: 0.32rem;
            color: #fff;
        }
    </style>
</head>

<body>
    <div class="box">
        <input id="text" type="hidden" />
        <div id="qrcode" class="walletAddressImg"></div>
        <div class="code">
            <a href="#">推广二维码</a>
        </div>
    </div>

    <script src="./jquery.js"></script>
    <script src="./qrcode.min.js"></script>
    <script>
        $(function () {
            var url = "www.baidu.com";
            makeCode(url);
        });

        var qrcode = new QRCode(document.getElementById("qrcode"), {
            width: 80,
            height: 80
        });

        function makeCode(url) {
            var elText = document.getElementById("text");
            var elTextVal = document.getElementById("text").value = url;
            if (!elText.value) {
                console.log("为空");
                elText.focus();
                return;
            }
            qrcode.makeCode(elTextVal);
        }

        // $("#text").on("blur", function () {
        //     makeCode();
        // }).on("keydown", function (e) {
        //     if (e.keyCode == 13) {
        //         makeCode();
        //     }
        // });
    </script>
</body>

</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值