ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ## 事件名为驼峰写法 ``` <button onClick={activateLasers}> Activate Lasers </button> ``` ## 阻止默认事件 ``` function ActionLink() { function handleClick(e) { e.preventDefault(); console.log('The link was clicked.'); } return ( <a href="#" onClick={handleClick}> Click me </a> ); } ``` ## bind 绑定this ``` constructor(props) { super(props); this.state = {isToggleOn: true}; // 为了在回调中使用 `this`,这个绑定是必不可少的 this.handleClick = this.handleClick.bind(this); } handleClick() { this.setState(state => ({ isToggleOn: !state.isToggleOn })); } ``` ## 向事件中传递参数 两中都可以 ``` <button onClick={(e) => this.deleteRow("123", e)}>Delete Row</button> <button onClick={this.deleteRow.bind(this, "123")}>Delete Row</button> ```