做網站活動頁面的時候,要為每個活動生成一個二維碼,雖然簡單,但還是習慣記錄下來。
jquery.qrcode.min.js是js的一個庫,主流的瀏覽器都支持:IE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile
方法: qrcode(),
參數:
text:要編碼的字符串地址
width:定義的寬度
height:定義的高度
background:背景色
foreground:前景色
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>生成二維碼</title>
<script type='text/javascript' src='http://cdn.staticfile.org/jquery/2.1.1/jquery.min.js'></script>
<script type="text/javascript" src="http://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
</head>
<body>
<div id="qrcode"></div>
</body>
<script>
$("#qrcode").qrcode({
width:64,
height:64,
text:"https://www.baidu.com/"
})
</script>
</html>
用qrcode.js生成二維碼,默認是canvas畫的
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>生成二維碼</title>
<script type="text/javascript" src="qrcode.js"></script>
</head>
<body>
<div id="qrcode"></div>
</body>
<script>
new QRCode(document.getElementById("qrcode"),"https://www.baidu.com/")
</script>
</html>
