javascript键盘事件

2025-05-07 09:08:37
推荐回答(3个)
回答1:

首先


这句的 onKeyPress 多余了,因为上面的 JS 代码已经给他绑定。
其次,因为这个

不可编辑,所以不会产生 keypress 事件。

给你改一下程序,监听 window 的 keypress,显示在指定区域。



JavaScript测试



Displaying Typed Characters


This document includes a simple script that displays the keys you type in the paragraph below. Type a few keys and try it.





回答2:

小小的改动了下。onKeyPress只支持有键盘输入的元素




无标题文档



Displaying Typed Characters


This document includes a simple script that displays the keys you type in the paragraph below. Type a few keys and try it.




在这里输入

回答3:

小改动看看效果




无标题文档



Displaying Typed Characters


This document includes a simple script that displays the keys you type in the paragraph below. Type a few keys and try it.