在输入框中按下一个按键时,弹出按键对应的键码值
有人会吗?求解!
原码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>a</title>
<style>
#tt {
width: 200px;
height: 30;
border: 4px solid yellow;
border-radius: 18px;
margin-top: 35%;
}
#txtBoder {
width: 210px;
height: 200px;
border-radius: 18px;
border: 4px solid paleturquoise;
}
</style>
</head>
<body>
<div id="txtBoder">
<input type="text" id="tt" placeholder="请按下一个按键~"/>
</div>
<script>
//请在下方写你的代码:当按下一个按键时,弹出按键对应的键码值
</script>
</body>
</html>
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>a</title>
<style>
#tt {
width: 200px;
height: 30;
border: 4px solid yellow;
border-radius: 18px;
margin-top: 35%;
}
#txtBoder {
width: 210px;
height: 200px;
border-radius: 18px;
border: 4px solid paleturquoise;
}
</style>
</head>
<body>
<div id="txtBoder">
<input type="text" id="tt" placeholder="请按下一个按键~" />
</div>
<script>
//请在下方写你的代码:当按下一个按键时,弹出按键对应的键码值
var ipt = document.getElementById('tt');
//keyup 键盘被松开时执行if
document.addEventListener('keyup', function (e) {
console.log(e.keyCode);
alert(e.keyCode)
})
</script>
</body>
</html>
效果: