使用二维码生成库 qrcode.js生成二维码
什么是 QRCode.js?
QRCode.js 是一个用于生成二维码的 JavaScript 库。主要是通过获取 DOM 的标签,再通过 HTML5 Canvas 绘制而成,不依赖任何库。
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
<script type="text/javascript" src="https://static.runoob.com/assets/qrcode/qrcode.min.js"></script>
<style>
</style>
</head>
<body>
<div id="qrcode"></div>
<input type="text" id="getval"/> <button id="send">点击生成二维码</button>
</body>
<script>
var qrcode = new QRCode(document.getElementById("qrcode"), {
width : 96,//设置宽高
height : 96
});
qrcode.makeCode("http://www.baidu.com");
document.getElementById("send").onclick = function() {
qrcode.makeCode(document.getElementById("getval").value);
}
</script>
</html>