代码示例:(标识:eg_js_events_onkeydown)
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
  alert("您在输入字段中按了一个键");
}
</script>
</head>
<body>

<p>当用户在输入字段中按键时,将触发函数。</p>

<input type="text" onkeydown="myFunction()">

</body>
</html>
运行结果: