使用JAVASCRIPT 方式建立二維碼
阿新 • • 發佈:2018-11-30
上個知識點講解了如何用Java生成和解析二維碼, 這個知識點講解如何用javascript建立二維碼圖片。 貌似javascript就不需要解析二維碼圖片了,沒有應用場景,就不講解析了。
首先需要第三方的js檔案:jquery.qrcode.min.js,還需要jquery的js,點選此處下載
用法很簡單:
$('#qrcode').qrcode({render:'canvas',text:"https://blog.csdn.net/weixin_41888813/article/category/7830453",width:260,height:260});
注: 其中的canvas還可以換成 table,用於在不支援html5的瀏覽器中使用。
<head> <meta http-equiv="Content-Type" content="text/html; charset=GBK"> <script src="js/jquery/2.0.0/jquery.min.js"></script> <script src="js/qrcode/jquery.qrcode.min.js"></script> </head> <div style="width:800px;margin:50px auto;text-align:center"> <h1>把字串: https://blog.csdn.net/weixin_41888813/article/category/7830453 轉換為二維碼</h1> <div id="qrcode"></div> </div> <script> $(function(){ $('#qrcode').qrcode({render:'canvas',text:"https://blog.csdn.net/weixin_41888813/article/category/7830453",width:260,height:260}); }); </script>
來源於: