JavaScript key handling and browser compatibility

依然范特西╮ 提交于 2019-12-03 07:17:48

See the following pages, they will answer your quetions:

onkeydown event, onkeypress event, keyCode property, charCode property, which property

The following article by Jan Wolter has never failed me and is far and away the best resource on browser key events I've seen: http://unixpapa.com/js/key.html. It answers all the questions you posed.

One thing to emphasize is that with careful use of the key event properties at your disposal you will almost certainly never need to sniff for a particular browser in your key handling code.

2015 update:

According to MDN event.charCode, event.keyCode and event.which have all been deprecated. event.key is the newest and hottest way to check which key has been pressed.

It looks easy to use, but browser support isn’t perfect. All we have now is partial support in Chrome 45+ (not out yet AFAIK), Firefox 23+ and IE 9+.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!