JS实现二维码生成

一. 前言

二维码又称QR Code,是一个近几年来移动设备上很流行的一种编码方式 , 它比传统的一维码(条形码)能存更多的信息,也能表示更多的数据类型。

二.代码展示

  • window.location.href = “https://blog.csdn.net/2301_76459194?spm=1011.2266.3001.5343”
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Suporka Vue App</title>
    <style>
        .container {
            padding: 60px;
            margin: 0 auto;
            line-height: 50px;
        }

        input {
            display: inline-block;
            width: 200px;
            height: 32px;
            line-height: 1.5;
            padding: 4px 7px;
            font-size: 12px;
            border: 1px solid #dcdee2;
            border-radius: 4px;
            color: #515a6e;
            background-color: #fff;
            background-image: none;
            position: relative;
            cursor: text;
            transition: border 0.2s ease-in-out, background 0.2s ease-in-out,
                box-shadow 0.2s ease-in-out;
        }

        button {
            color: #fff;
            background-color: #19be6b;
            border-color: #19be6b;
            outline: 0;
            vertical-align: middle;
            line-height: 1.5;
            display: inline-block;
            font-weight: 400;
            text-align: center;
            -ms-touch-action: manipulation;
            touch-action: manipulation;
            cursor: pointer;
            background-image: none;
            border: 1px solid transparent;
            white-space: nowrap;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            padding: 5px 15px 6px;
            font-size: 12px;
            border-radius: 4px;
            transition: color 0.2s linear, background-color 0.2s linear,
                border 0.2s linear, box-shadow 0.2s linear;
        }

        #qrcode {
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <div class="container">
        <input type="text" placeholder="请输入您想转化成二维码的字符串" id="input" />
        <button onclick="creatQRcode()">一键生成</button>
        <div id="qrcode"></div>
    </div>
    <script src="https://zxpsuper.github.io/Demo/qrcode/qrcode-dev.js"></script>
    <script type="text/javascript">
        var qrcode = null;
        function creatQRcode() {
            document.getElementById("qrcode").innerHTML = "";
            // 设置要生成二维码的链接
            // qrcode = new QRCode(document.getElementById("qrcode"), "http://www.baidu.com");  
            // 设置要生成二维码的样式
            qrcode = new QRCode(document.getElementById("qrcode"), {
                text: document.getElementById("input").value,
                width: 200,
                height: 200,
                colorDark: "#000000",
                colorLight: "#ffffff",
                correctLevel: QRCode.CorrectLevel.H
            });
        }
    </script>
</body>

</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

加油乐

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

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

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

打赏作者

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

抵扣说明:

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

余额充值