<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="js/react.js"></script> <script src="js/react-dom.js"></script> <script src="js/browser.min.js"></script> </head> <body> <div id="example_1"></div> <div id="example_2"></div> <script type="text/babel"> var A = React.createClass({ getInitialState:function(){ return {count:0}; }, render:function(){ return <div>{this.state.count}</div> }, eventClick:function(){ this.setState({ count: this.state.count+1, }) } }); ReactDOM.render(<div> <A class="a"/> <input type="button" onClick={A.eventClick}/> </div>, document.getElementById("example_1") ); </script> </body> </html>
写法不正确,你的组件是渲染到A上了,和下面的input 没关系。
一周热门 更多>