当在元素上触发 onclick 事件时,如何从事件对象(与单击的 .target 元素相对)获取事件附加到的元素?
最佳答案
您可以访问 currentTarget
property相反。
来自 MDN :
currentTarget
- Identifies the current target for the event, as the event traverses the DOM. It always refers to the element the event handler has been attached to as opposed toevent.target
which identifies the element on which the event occurred.
关于处理程序附加到的 Javascript 获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33923337/