gpt4 book ai didi

处理程序附加到的 Javascript 获取元素

转载 作者:行者123 更新时间:2023-11-29 15:32:00 25 4
gpt4 key购买 nike

当在元素上触发 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 to event.target which identifies the element on which the event occurred.

关于处理程序附加到的 Javascript 获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33923337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com