摘录自 MDN:
The currentTarget read-only property of the Event interface identifies the current target for the event, as the event traverses the DOM. It always refers to the element to which the event handler has been attached, as opposed to Event.target, which identifies the element on which the event occurred and which may be its descendant.
以上意思是:
1.currentTarget是注册该事件的对象,可以理解为: element.addEventListener(‘xxx’, handler);
handler触发的时候,e.currentTarget为element。
2.target是当前handler事件触发的元素,不仅是currentTarget可以触发,也可能是currentTarget的后代元素。
h5点击事件 e.currentTarget 与 e.target区别
最新推荐文章于 2024-04-07 08:07:50 发布