简体   繁体   English

浏览器键事件是否仅对焦点元素触发(冒泡)?

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

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.否则,我有一些代码不能正确地让这些事件冒泡。

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.如果您正在查看输入的父级,并且焦点更改到窗口,则无法在父级找到下一个键事件(因为它不在那里),但您始终可以在文档级别找到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM