浏览器关键事件是否只会触发焦点元素? [英] Do browser key events fire (bubble) only to elements in focus?

查看:152
本文介绍了浏览器关键事件是否只会触发焦点元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实验证据使我相信,关键(上,下,按)事件只会触发元素



这种行为可能是直观的,明显的和/或理想的,但是并没有在任何地方见到过,所以我希望社群能证实我的理论。



谢谢!

解决方案

关键事件总是针对具有焦点的元素,并冒泡直到取消。



输入元素或文档/窗口本身作为目标,并具有焦点。

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


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!

解决方案

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.

这篇关于浏览器关键事件是否只会触发焦点元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆