您的位置:首页 > Web前端 > JQuery

动态生成二维码小案例

2017-03-30 11:07 162 查看
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>练习jqueryui框架</title>

<link rel="stylesheet" href="jquery-ui.min.css">
<script src="jquery.min.js"></script>
<script src="jquery-ui.min.js"></script>

        <script src="jquery.qrcode.min.js"></script>
</head>
<body>

        <input class="num1" type="text">
<input class="num2" type="text">

         <button type="submit">提交</button>

         <div id="code"></div>
<script>

            function toUtf8(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));    

       
4000
                    out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    

                        } else {    

                            out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));    

                            out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));    

                        }    

                    }    

                    return out;    

                   }

                     $('button').on('click',function(){

                         $('#code').empty();

                         var htmlStr = "房间号:"+$('.num1').val()+","+"桌号: "+$('.num2').val()

                         var str = toUtf8(htmlStr); 

                         $('#code').qrcode(str);

                     })

            
</script>
</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息