Edit The Code:
See Result »
Try it Yourself - ©
w3big.com
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>本教程 React 实例</title> <script src="http://static.w3big.com/assets/react/react-0.14.7/build/react.min.js"></script> <script src="http://static.w3big.com/assets/react/react-0.14.7/build/react-dom.min.js"></script> <script src="http://static.w3big.com/assets/react/browser.min.js"></script> </head> <body> <div id="example"></div> <script type="text/babel"> var LikeButton = React.createClass({ getInitialState: function() { return {liked: false}; }, handleClick: function(event) { this.setState({liked: !this.state.liked}); }, render: function() { var text = this.state.liked ? '喜欢' : '不喜欢'; return ( <p onClick={this.handleClick}> 你<b>{text}</b>我。点我切换状态。 </p> ); } }); React.render( <LikeButton />, document.getElementById('example') ); </script> </body> </html>