[英]onClick event of child component is not getting triggered for stacked parent and child component
我有以下兩個組件,分別具有onClick()
處理函數。 問題是doSomethingElse
永遠都不會獲取,而是直接調用doSomething
。
<ParentComponent onClick={this.doSomething}>
<ChildComponent onClick={this.doSomethingElse} />
</Parent>
Child
被示出為在像proover parent
使用z-index
。
class Parent extends React.Component {
constructor(props) {
super(props);
}
handleP = (e) => {
alert("parent")
};
render() {
return (
<div onClick={this.handleP} style={{
left: 100,
top: 100,
zIndex: 100,
position: 'absolute',
}}>
Parent Text
<Child />
</div>
)
}
}
class Child extends React.Component {
constructor(props) {
super(props);
}
handleC = (e) => {
alert("child")
};
render() {
return (
<div onClick={this.handleC} style={{
left: 1,
top: 1,
zIndex: 1000,
position: 'absolute',
}}>
Child Text
</div>
)
}
}
React.render(
<Parent />,
document.getElementById('react_example')
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.