代码示例:(标识:dhtm_event_onkeypress)
<html>
<head>
<script type="text/javascript">
function message()
{
alert("当您按键盘上的按键时,会触发这个提示框。")
}
</script>
</head>

<body onkeypress="message()">
<p>当敲击键盘上的按键时,会发生 onkeypress 事件。</p>
<p>要触发 onkeypress 事件,请确保窗口拥有焦点。</p>
</body>

</html>
运行结果: