疑惑???
但是为什么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按键