Do browser key events fire (bubble) only to elements in focus?

别来无恙 提交于 2019-12-12 23:25:32

问题


Experimental evidence has led me to believe that key (up, down, press) events fire (in bubble phase) only to elements in focus.

This behavior may be intuitive, obvious and/or desirable, but haven't seen this documented anywhere, so I was hoping the community would confirm my "theory".

Otherwise, I have some code that's not properly letting these events bubble up.

Thanks!


回答1:


key events are always targeted to the element that has focus, and bubble up until cancelled.

You cannot press a key without an input element or the document/window itself being the target, and having the focus.

If you are looking at the parent of an input, and the focus changes to the window, you cannot find the next key event at the parent (because it isn't there), but you always find it at the document level.



来源:https://stackoverflow.com/questions/10214547/do-browser-key-events-fire-bubble-only-to-elements-in-focus

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