很簡單,直接貼代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>qrcode</title>
</head>
<body>
<div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="qrcode.min.js"></script>
<script type="text/javascript">
//初始化存放二維碼的div
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 100,
height : 100
});
//window.location.href獲取到URL
qrcode.makeCode(window.location.href);
</script>
</body>
</html>