这里主要介绍的是经过onMouseEnter,onMouseLeave事件来改变状态this
var Link = React.createClass({ getInitialState: function(){ return {hover: false} }, toggleHover: function(){ this.setState({hover: !this.state.hover}) }, render: function() { var linkStyle; if (this.state.hover) { linkStyle = {backgroundColor: 'red'} } else { linkStyle = {backgroundColor: 'blue'} } return( <div> <a style={linkStyle} onMouseEnter={this.toggleHover} onMouseLeave={this.toggleHover}>Link</a> </div> ) }
但愿你们喜欢,也但愿你们指点错误,也能够加入qq群439667347,你们一块儿讨论,一块儿进步,后续更新中...code