使用jquery.qrcode產生二維碼

來源:互聯網
上載者:User

標籤:分享   src   highlight   簡單   elements   idt   string   jquery   儲存   

jQuery 的 qrcode 外掛程式就可以在瀏覽器端產生二維碼圖片. 這個外掛程式的使用非常簡單:

 

1、首先在頁面中加入jquery庫檔案和qrcode外掛程式。

代碼  
  1. <script type="text/javascript" src="jquery.js"></script>  
  2. <script type="text/javascript" src="jquery.qrcode.min.js"></script>   

 

2、在頁面中需要顯示二維碼的地方加入以下代碼。

代碼  
  1. <div id="qrcodeCanvas"></div>  
  2. <script>  
  3. jQuery(‘#qrcodeCanvas‘).qrcode({  
  4.     width   : 300,  
  5.     height  : 300,  
  6.     text    : http://www.baidu.com  
  7. });   
  8. </script>  

上面這段代碼產生一張 300x300 的canvas二維碼, 它包含的資訊便是百度的網址。

 

3、用JS將上面的canvas內容轉換成圖片(png或jpg格式使其可以儲存)。

首先設個img標籤:

代碼  
  1. <img id="image" src="">  

最後用JS代碼轉換:

代碼  
  1. var image = document.getElementById("image");  
  2. var canvas = document.getElementById("qrcodeCanvas").getElementsByTagName("canvas")[0];  
  3. image.src = canvas.toDataURL("image/png");  

完成。

轉自:http://coyotestark.iteye.com/blog/2265027

使用jquery.qrcode產生二維碼(轉)

聯繫我們

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