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.js"></script> <script src="http://static.w3big.com/assets/react/react-0.14.7/build/react-dom.js"></script> <script src="http://static.w3big.com/assets/react/browser.min.js"></script> </head> <body> <div id="message" align="center"></div> <script type="text/babel"> var Counter = React.createClass({ getInitialState: function () { return { clickCount: 0 }; }, handleClick: function () { this.setState(function(state) { return {clickCount: state.clickCount + 1}; }); }, render: function () { return (<h2 onClick={this.handleClick}>点我!点击次数为: {this.state.clickCount}</h2>); } }); ReactDOM.render( <Counter />, document.getElementById('message') ); </script> </body> </html>