<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#qrcode {
width: 160px;
height: 160px;
margin-top: 15px;
}
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
</head>
<body>
<input id="text" type="text" value="http://www.runoob.com" /><br />
<div id="qrcode"></div>
<script>
var qrcode = new QRCode("qrcode");
function makeCode() {
var elText = document.getElementById("text");
if (!elText.value) {
elText.focus();
return;
}
qrcode.makeCode(elText.value);
}
makeCode();
document.querySelector("#text").addEventListener('blur', function() {
makeCode();
});
document.querySelector("#text").addEventListener('keydown', function(e) {
if (e.keyCode == 13) {
makeCode();
}
});
</script>
</body>
</html>
js生成二维码
最新推荐文章于 2024-05-09 02:57:36 发布