生成二维码功能(js前端)
生成二维码需要引入qrcode.js和jquery.min.js
<!DOCTYPE html>
<head>
<title>二维码</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/qrcode.js"></script>
</head>
<body>
<input id="text" type="text" value="www.baidu.com" style="width:200px;" />
<button id="btn" onclick="makeCode()">生成</button><br />
<div id="qrcode" style="width:100px; height:100px;margin-top: 15px;"></div>
<script type="text/javascript">
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 200,
height : 200
});
function makeCode () {
var elText = document.getElementById("text");
qrcode.makeCode(elText.value);
}
</script>
</body>
</html>