Reactjs 如何阻止e.target指向react中的子元素?
我有一个组件(比如a),其中有很多子组件。我想在此组件上调用onmousemove事件。回调函数中的event.target应该始终指向div,但当我将鼠标悬停在该函数中的子元素上时,event.target指向正在悬停的子元素 如何使此事件始终指向主组件Reactjs 如何阻止e.target指向react中的子元素?,reactjs,mouseover,Reactjs,Mouseover,我有一个组件(比如a),其中有很多子组件。我想在此组件上调用onmousemove事件。回调函数中的event.target应该始终指向div,但当我将鼠标悬停在该函数中的子元素上时,event.target指向正在悬停的子元素 如何使此事件始终指向主组件 <div onMouseMove={(e) => this.test(e)}> <p>hello</p> <span>hi this is a test</p&g
<div onMouseMove={(e) => this.test(e)}>
<p>hello</p>
<span>hi this is a test</p>
</div>
..
..
..
test(e) {
console.log(e.target);
}
this.test(e)}>
你好
嗨,这是一个测试
..
..
..
测试(e){
console.log(如target);
}
预期产出:
。
//始终
实际产量:
。
//将鼠标悬停在仅div部分上时
。
//当鼠标悬停在p etc上时,有e.currentTarget
,它指向您期望的div