<分区>
我正在尝试使用 refs 是 ReactJs,通过单击按钮来聚焦文本框。
但我收到以下错误消息:-
bundle.js:114 Uncaught TypeError: Cannot read property 'focus' of undefined
源代码
class FocusText extends Component{
handleClick(){
this.refs.myTextInput.focus();
}
render(){
return(
<div>
<input type="text" ref="myTextInput"/>
<input type="button"
value="Focus the text input"
onClick={this.handleClick.bind(this)}/>
</div>
);
}
}
React.render(<FocusText/>, document.getElementById('root'));