这里是演示:https://codesandbox.io/s/rough-sun-znrd2
我在a
的子元素button
处调用了stopPropagation,并且a
也没有收到click
事件。但是页面仍然可以导航。
代替stopPropagation
防止事件冒泡,您需要使用event.preventDefault
取消默认行为
const onClickButton = (event: MouseEvent) => {
console.log("click Button");
event.preventDefault();
aElm.click();
};