js 生成二维码

发布时间 2024-01-02 13:50:08作者: 3939!

1:引入js文件

@*二维码生成器*@
<script src="~/BigScreen/js/qrcodes.min.js"></script>

2:html

 <div class="hgz-QRcode">
   <div id="qrcode" style="    padding-right: 10px;padding-top: 14px;"></div>
 </div>
View Code

3:js

window.onload = function () {
   //二维码生成start
        var urlcode = document.location.href;
         //本地运行出来,需要替换ip才能扫出来
        var targetStr = "localhost";
        var index = urlcode.indexOf(targetStr);
        if (index!=-1) {
            urlcode = urlcode.replace("localhost", "192.168......");
        }
       
        console.log(urlcode); var qrcode = new QRCode(document.getElementById("qrcode"), {
            text: urlcode,
            width: 100,
            height: 100,
            colorDark: "#000000",
            colorLight: "#ffffff",
            correctLevel: QRCode.CorrectLevel.H
        });

        //二维码生成end
}    
View Code