用jquery包將字串變成二維碼

來源:互聯網
上載者:User

用jquery包將字串變成二維碼

  將一個字串(可以是中文,在產生二維碼圖片之前將中文轉碼)產生二維碼圖片,如果想要帶log的二維碼,可以在產生後的二維碼中間部位自己添加一個小log,log圖片不要太大,不然就掃描不出內容了。

<html xmlns="http://www.w3.org/1999/xhtml"><head>    <title></title>    <script src="js/jquery-1.8.3.js" type="text/javascript"></script>    <script src="js/qrcode.js" type="text/javascript"></script>    <script src="js/jquery.qrcode.js" type="text/javascript"></script>    <script type="text/javascript">        $(function () {            $("#bt").bind("click", function () {                text = $("#text").val();                $("#div_div").qrcode(utf16to8(text));            })        })        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><input type="text" id="text" /><input type="button" value="shengc" id="bt" /><div id="div_div" style="width:400px;height:400px;border:1px solid #000;"></div></body></html>

這裡引用了三個js包,其中一個是jquery包,這個隨便版本,另外兩個就是畫二維碼用的js包了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.