QRCode.js -- 用 Javascript 生产二维码
生活随笔
收集整理的這篇文章主要介紹了
QRCode.js -- 用 Javascript 生产二维码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
QRCode.js是一個生成二維碼的JS庫。QRCode.js支持在DOM中使用跨瀏覽器Canvas和table標簽的。 QRCode.js不依賴其他JS庫。
基本用法:
<div?id="qrcode"></div> <script?type="text/javascript"> new?QRCode(document.getElementById("qrcode"),?"http://jindo.dev.naver.com/collie"); </script>還可以添加其它選項:
<div?id="qrcode"></div> <script?type="text/javascript"> var?qrcode?=?new?QRCode(document.getElementById("qrcode"),?{text:?"http://jindo.dev.naver.com/collie",width:?128,height:?128,colorDark?:?"#000000",colorLight?:?"#ffffff",correctLevel?:?QRCode.CorrectLevel.H }); </script>也可以使用一些方法:
瀏覽器兼容性:
IE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile 等等
案例演示:
<!DOCTYPE?html> <html> <head?lang="en"><meta?charset="UTF-8"><meta?http-equiv="Content-Type"?content="text/html;?charset=UTF-8"?/><meta?name="viewport"?content="width=device-width,initial-scale=1,user-scalable=no"?/><title></title> </head> <body><input?id="text"?type="text"?value="http://dapengtalk.blog.51cto.com"?style="width:80%"?/><br?/> <div?id="qrcode"?style="width:100px;?height:100px;?margin-top:15px;"></div><script?src="js/jquery-1.8.3.min.js"></script> <script?src="js/qrcode.js"></script> <script>var?qrcode?=?new?QRCode(document.getElementById("qrcode"),?{width?:?100,height?:?100});function?makeCode?()?{var?elText?=?document.getElementById("text");if?(!elText.value)?{alert("Input?a?text");elText.focus();return;}qrcode.makeCode(elText.value);}makeCode();$("#text").on("blur",?function?()?{makeCode();}).on("keydown",?function?(e)?{if?(e.keyCode?==?13)?{makeCode();}});</script> </body> </html>頁面截圖:
掃描二維碼:
Github 地址:https://github.com/davidshimjs/qrcodejs
轉載于:https://blog.51cto.com/dapengtalk/1879568
總結
以上是生活随笔為你收集整理的QRCode.js -- 用 Javascript 生产二维码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基本概念学习(9001)---指令系统
- 下一篇: mysql 隔离级别和锁相关