[js]keypress和keydown的区别

疑惑???

但是为什么onkeydown和onkeypress的e.keyCode不一样呢?

疑惑解答

The events are for completely different purposes. Use keyup
and keydown for identifying physical keys and keypress for identifying typed characters. The two are fundamentally different tasks with different events; don't try to mix the two.
In particular, keyCode on keypress events is usually redundant and shouldn't be used (except in older IE); for printable keypresses it's usually the same as which and charCode, although there is some variation between browsers.

知识补充:
e.which不区分小键盘,比如小键盘和大键盘的1都是一个值。
区分大小写吗?
keypress事件监听不到shift按键

相关连接:
keypress and keyup - why is the keyCode different?

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容