var keyCode = event.keyCode
//根据keycode判断按下的是哪个键
})
参考代码:
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
document.onkeydown =function (e) {
alert("你按下了:"+e.key)
}
</script>
</body>
</html>
效果:
代码仅供参考