有关DOM Event事宜和自定义Event相干文档文章引见速记

搞清Event.currentTarget、Event.target、Event.srcElement之间的关联

Event.currentTarget: https://developer.mozilla.org…

Event.target: https://developer.mozilla.org…

Event.srcElement: https://developer.mozilla.org…

  • Event.currentTarget指的事宜绑定时的DOM对象;
  • Event.target指的事宜发作地点的DOM对象,比方你的把事宜能够绑在父元素上,点击子元素,此时Event.currentTarget指的是父元素Event.target指的是你点击的子元素
  • Event.srcElement是一个非规范属性,是老IE关于Event.target的完成,指的事宜发作地点的DOM对象。

自定义事宜相干的API

疾速相识怎样自定义事宜和触发的demo:https://developer.mozilla.org…

CustomEvent Constructor 用来建立自定义事宜的API(规范引荐):https://developer.mozilla.org…

document.createEvent()(老旧浏览器建立自定义事宜API,已被烧毁,不引荐,但能够作为兼容旧浏览器运用):https://developer.mozilla.org…

怎样应用document.createEvent()来完成CustomEvent Constructor 的兼容: https://github.com/tuxsudo/po…

IE8不支持document.createEvent()和CustomEvent Constructor,建立自定义能够应用 propertychange 范例事宜
来兼容,张鑫旭先生在js-dom自定义事宜一文中有引见这类技能,重点能够浏览【四、伪DOM自定义事宜】一节: https://www.zhangxinxu.com/wo…

Comparison of Event Targets

https://developer.mozilla.org…

PropertyDefined inPurpose
event.targetDOM Event Interface <p>The DOM element on the lefthand side of the call that triggered this event, eg:</p> <pre class=”eval line-numbers language-html”>element.dispatchEvent(event)<span class="line-numbers-rows" aria-hidden="true"><span></span></span></pre>
event.currentTargetDOM Event InterfaceThe EventTarget whose EventListeners are currently being processed. As the event capturing and bubbling occurs this value changes.
event.relatedTargetDOM MouseEvent InterfaceIdentifies a secondary target for the event.
event.explicitOriginalTargetnsIDOMNSEvent.idl<span title=”This API has not been standardized.”> </span> If the event was retargeted for some reason other than an anonymous boundary crossing, this will be set to the target before the retargeting occurs. For example, mouse events are retargeted to their parent node when they happen over text nodes (bug 185889), and in that case .target will show the parent and .explicitOriginalTarget will show the text node.
Unlike .originalTarget, .explicitOriginalTarget will never contain anonymous content.
event.originalTargetnsIDOMNSEvent.idl<span title=”This API has not been standardized.”> </span> The original target of the event, before any retargetings. See Anonymous Content#Event_Flow_and_Targeting for details.

MouseEvent.relatedTarget

https://developer.mozilla.org…

The MouseEvent.relatedTarget read-only property is the secondary target for the event, if there is one. That is:

Event nametargetrelatedTarget
focusinThe EventTarget receiving focusThe EventTarget losing focus
focusoutThe EventTarget losing focusThe EventTarget receiving focus
mouseenterThe EventTarget the pointing device entered toThe EventTarget the pointing device exited from
mouseleaveThe EventTarget the pointing device exited fromThe EventTarget the pointing device entered to
mouseoutThe EventTarget the pointing device exited fromThe EventTarget the pointing device entered to
mouseoverThe EventTarget the pointing device entered toThe EventTarget the pointing device exited from
dragenterThe EventTarget the pointing device entered toThe EventTarget the pointing device exited from
dragexitThe EventTarget the pointing device exited fromThe EventTarget the pointing device entered to

关于MouseEvent.relatedTarget用法的演示: https://jsfiddle.net/uTe99

Interface Event


[Constructor(DOMString type, optional EventInit eventInitDict),

 Exposed=(Window,Worker,AudioWorklet)]

interface Event {

  readonly attribute DOMString type;

  readonly attribute EventTarget? target;

  readonly attribute EventTarget? srcElement; // historical

  readonly attribute EventTarget? currentTarget;

  sequence<EventTarget> composedPath();



  const unsigned short NONE = 0;

  const unsigned short CAPTURING_PHASE = 1;

  const unsigned short AT_TARGET = 2;

  const unsigned short BUBBLING_PHASE = 3;

  readonly attribute unsigned short eventPhase;



  void stopPropagation();

           attribute boolean cancelBubble; // historical alias of .stopPropagation

  void stopImmediatePropagation();



  readonly attribute boolean bubbles;

  readonly attribute boolean cancelable;

           attribute boolean returnValue; // historical

  void preventDefault();

  readonly attribute boolean defaultPrevented;

  readonly attribute boolean composed;



  [Unforgeable] readonly attribute boolean isTrusted;

  readonly attribute DOMHighResTimeStamp timeStamp;



  void initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false); // historical

};



dictionary EventInit {

  boolean bubbles = false;

  boolean cancelable = false;

  boolean composed = false;

};
    原文作者:而井
    原文地址: https://segmentfault.com/a/1190000017137551
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞