如何检查使用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>热门推荐
1 带清的简短祝福语
7 送蛇的祝福语简短
8 聚餐会祝福语简短
10 入伙英文祝福语大全简短
11 弟弟生日祝福语简短的话
12 20岁简短生日祝福语
13 文艺结婚祝福语短语简短
14 校长退休文案祝福语简短
15 订婚新发言简短祝福语
16 夸赞老师祝福语搞笑简短
17 38节贺卡简短祝福语
18 老哥出门祝福语简短语