h5開發app之線上產生二維碼

來源:互聯網
上載者:User

標籤:images   跳轉   bsp   png   效果   orm   需要   qrcode   圖片   

h5通過jquery和qrcode線上產生二維碼

首先我們需要下載一個qrcode.js檔案,然後依次引入jquery和qrcode檔案。

1、建立一個輸入框以便做示範使用:

<input id="text" type="text" value="http://www.baidu.com" style="width:80%" />

2、建立一個div以用來放置二維碼圖片(div的id定義為“qrcode”):

<div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>

3、插入js代碼:

 1 var qrcode = new QRCode(document.getElementById("qrcode"), { 2     width : 100, 3     height : 100 4 }); 5  6 function makeCode () {         7     var elText = document.getElementById("text"); 8      9     if (!elText.value) {10         alert("Input a text");11         elText.focus();12         return;13     }14     15     qrcode.makeCode(elText.value);16 }17 18 makeCode();19 20 $("#text").21     on("blur", function () {22         makeCode();23     }).24     on("keydown", function (e) {25         if (e.keyCode == 13) {26             makeCode();27         }28     });29 </script

 這樣就可以,線上產生二維碼了!

就是我們的代碼,試試用手機掃描下會不會跳轉到百度首頁。

 

h5開發app之線上產生二維碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.