且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Event.target,Event.toElement和Event.srcElement有什么区别?

更新时间:2023-12-04 12:01:22

事件目标是调度事件的元素:


活动的对象>使用 DOM事件
进行定位。事件目标是 Event.target
属性。

The object to which an event is targeted using the DOM event flow. The event target is the value of the Event.target attribute.

srcElement 是获取目标的IE非标准方式

当前事件目标是具有当前调用的事件侦听器的元素:

The current event target is the element which has the event listener which is currently invoked:


在事件流中,当前事件目标是与$ a bref相关联的对象,其中事件处理程序。这个
对象可以是事件目标本身或者一个它的祖先。
事件从$ b传播时,当前事件目标会发生变化$ b通过事件流的各种阶段反对。
当前事件目标是
的值 Event.currentTarget 属性。

In an event flow, the current event target is the object associated with the event handler that is currently being dispatched. This object MAY be the event target itself or one of its ancestors. The current event target changes as the event propagates from object to object through the various phases of the event flow. The current event target is the value of the Event.currentTarget attribute.

使用事件监听器中的此是获取当前事件目标的常用(和标准)方式。

Using this inside an event listener is a common (and standard) way to obtain the current event target.

某些类型的事件具有 relatedTarget

Some kind events have a relatedTarget:


用于识别次要 EventTarget
,具体取决于事件的类型。

Used to identify a secondary EventTarget related to a UI event, depending on the type of event.

fromElement toElement 是IE的非标准方式获取 relatedTarget

fromElement and toElement are IE non-standard ways to obtain the relatedTarget.