Event.toElement、Event.srcElement区别在哪?
我有以下代码:
document.oncontextmenu = function(evt) {
evt = evt || window.event;
console.log(evt.target, evt.toElement, evt.srcElement);
};
通过在< div class =“foo”>< / div>上单击鼠标右键,返回以下内容:
div.foo, div.foo, div.foo
通过在< input>上单击鼠标右键,返回:
input, input, input
所有似乎都带来了相同的结果.是否存在其中一种用途与其他用途不同的情况?
event target是调度事件的元素:
The object to which an 07001 is targeted using the 07002. The event target is the value of the 07003
attribute.
srcElement是获取目标的IE非标准方式.
current event target是具有当前调用的事件侦听器的元素:
In an event flow, the current event target is the object associated
with the 07005 that is currently being dispatched. This
object MAY be the 07000 itself or one of its ancestors.
The current event target changes as the 07001 propagates from
object to object through the various 07008 of the event flow.
The current event target is the value of the
07009 attribute.
在事件监听器中使用它是获取当前事件目标的常用(和标准)方法.
某种活动有relatedTarget:
Used to identify a secondary 070011 related to a UI event,
depending on the type of event.
fromElement和toElement是获取relatedTarget的IE非标准方法.