html生成二维码(识别长按)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/taowuhua0505/article/details/101055728

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="//cdn.bootcss.com/jquery/3.1.1/jquery.js"></script>
        <script src="//cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
        <script type="text/javascript">
            $(function () {  
                var text ="${strrest}";
                 var qrcode= $('#divOne').qrcode(utf16to8(text)).hide(); 
                 console.info(qrcode);
                    var canvas=qrcode.find('canvas').get(0);  
                    console.info(canvas);
                    $('#imgOne').attr('src',canvas.toDataURL('image/jpg'));
                    })                    
                    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>
    </head>
    <body>
        <div id="divOne"></div> 
         <img id='imgOne' /> 
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/taowuhua0505/article/details/101055728