700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > React 阻止默认事件和阻止冒泡

React 阻止默认事件和阻止冒泡

时间:2019-09-03 00:06:11

相关推荐

React 阻止默认事件和阻止冒泡

给 a 标签添加一个事件

阻止默认事件

e.preventDefault();

class view extends Component {onAtag(e) {// 阻止默认事件 放置跳转e.preventDefault();console.log("烦烦烦滚滚");}render() {return (<div><ahref='true'onClick={(e) => {this.onAtag(e);}}></a></div>);}}

阻止冒泡

e.stopPropagation();

class view extends Component {onDiv() {console.log("div");}onDivAtag(e) {e.preventDefault();// 阻止事件冒泡e.stopPropagation();console.log("div_aaaaaa");}render() {return (<div><divonClick={() => {this.onDiv();}}><ahref='true'onClick={(e) => {this.onDivAtag(e);}}></a></div></div>);}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。