我有这个组件的代码:
const myCardItem = ({ item }) => {
function clickItem(){
alert('Item clicked');
}
function clickMe(){
alert('Button clicked');
}
return (
<div className="myCardItem" onClick={clickItem}>
<i className="fa fa-clock-o"/> {item.planDate}
<br />
<i className="fa fa-location-arrow"/> {item.destination}
<br />
<Button bsStyle="primary" onClick={clickMe}>Click Me</Button>
</div>
);
}
如果我点击按钮,会先出现以下内容:
![enter image description here](https://istack.dev59.com/0SicQ.webp)
![enter image description here](https://istack.dev59.com/2GXN2.webp)
如何防止父级点击被调用?
在clickMe()中使用return false并不容易...
stopPropagation()
- Deckerz