04-ref 发表于 2018-05-03 | 分类于 前端-05-react | 123456789101112131415161718var MyComponent = React.createClass({ handleClick: function() { alert(this.myTextInput.value); }, render: function() { return ( <div> <input type="text" ref={(ref) => this.myTextInput = ref} /> <input type="button" value="Focus the text input" onClick={this.handleClick} /> </div> ); }});ReactDOM.render( <MyComponent />, document.body); 这里ref在设置的时候加上 ref={(ref)=>this.myTextInput=ref}