<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>子组件给父组件传值</title> <script src="https://cdn.bootcss.com/react/15.4.2/react.min.js"></script> <script src="https://cdn.bootcss.com/react/15.4.2/react-dom.min.js"></script> <script src="https://cdn.bootcss.com/babel-standalone/6.22.1/babel.min.js"></script> </head> <body> <div class="example"></div> <script type="text/babel"> var Item = React.createClass({ render:function(){ return ( <div> <input type="text" onChange={this.props.handleSonChange}/> </div> ) } }); var Box = React.createClass({ getInitialState:function(){ return {money:200}; }, handleSonChange:function(event){ this.setState({money:event.target.value}); }, render:function(){ <div> <span>{this.state.money}</span> <Item handleSonChange={this.handleSonChange()}/> </div> } }) ReactDOM.render( <Box/>, document.getElementById('example') ); </script> </body> </html>
哪里写错了,报错信息我都看不懂
Caballarii
烦恼般若舟
相关分类