Jquery生成二维码(微信中长按图片识别二维码功能)

时间:2017-03-07 08:10:50   收藏:0   阅读:615
<!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>

  解决项目中  在微信端生成的图片 长按具有识别二维码选项的功能。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!