如何检查使用jQuery已按下的键?
要检查按下了哪个键,请使用onkeydown属性。
示例
您可以尝试运行以下代码来获取按下哪个键:
<!DOCTYPE html>
<html>
<body>
<p>Press a key in the below box to get which key is pressed.</p>
<input type="text" size="10" onkeydown="demoFunction(event)">
<p id="test"></p>
<script>
function demoFunction(event) {
var a = event.key;
document.getElementById("test").innerHTML = "You've pressed the key: " + a;
}
</script>
</body>
</html>热门推荐
10 在爸妈生日祝福语简短
11 新年贺卡祝福语 文案简短
12 升学红包祝福语大全简短
13 礼仪队元旦祝福语简短
14 新年日文祝福语大全简短
15 小博士贺卡祝福语简短
16 老板提新车祝福语简短
17 复古婚礼祝福语高级简短
18 父母生日祝福语 简短独特