发新话题
打印

jquery 的keypress(), ff,ie,chrome中的区别

jquery 的keypress(), ff,ie,chrome中的区别

As for e.keyCode VS e.which... From my tests, Chrome and IE8: the keypress() handler will only get triggered for normal characters (i.e. not Up/Down/Ctrl), and both e.keyCode and e.which will return the ASCII code. In Firefox however, all keys will trigger keypress(), BUT: for normal characters e.which will return the ASCII code and e.keyCode will return 0, and for special characters (e.g. Up/Down/Ctrl) e.keyCode will return the keyboard code, and e.which will return 0. How fun.

1.在 chrome和ie中,keypress只能监听字符键,不能监听上、下、左、右、ctrl键。在e.keyCode中可取得 ascii码
2. 在ff中,可监听所有按键,当是非字符键时,e.which为空,e.keycode为键盘码(扫描码);当是字符码时,e.which为ascii码

TOP

===========================================================================
                   ctrls                                                                 chars
ie,chrome     -/-                                                                 e.keyCode == e.which == ?
ff                   e.which == 0, e.keyCode==扫描码         e.which = ?, e.keyCode == 0
============================================================================
综上所述,e.which == 0 时,为控制键!!

TOP

发新话题