event.currentTarget与event.target的区别介绍_javascript技巧
来源:动视网
责编:小采
时间:2020-11-27 21:06:27
event.currentTarget与event.target的区别介绍_javascript技巧
event.currentTarget与event.target的区别介绍_javascript技巧:event.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 eve
导读event.currentTarget与event.target的区别介绍_javascript技巧:event.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 eve

event.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.
即,event.currentTarget指向事件所绑定的元素,而event.target始终指向事件发生时的元素。翻译的不专业,好拗口啊,还是直接上测试代码吧:
代码如下:
click here!
script>
输出如下:
当点击click here!时click会向上冒泡,输出如下:
#inner
click here!
click here!
#wrapper
…
click here!
当点击click here!时click会向上冒泡,输出如下:
#wrapper
…
…
*/
script>
event.currentTarget与event.target的区别介绍_javascript技巧
event.currentTarget与event.target的区别介绍_javascript技巧:event.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 eve