【发布时间】:2017-01-02 19:51:16
【问题描述】:
我有一个带输入的组件,有什么方法可以使用名称来集中注意力吗?
<div onClick={this.handleClick.bind(this)}>
... Some more code ...
<input type="text" name={this.props.name} onChange={this.props.onChange} autoFocus/>
... Some more code ...
</div>
点击父 div 时,我附加了一个点击事件。
handleClick(e) {
// Need to focus may be using refs, but not sure how to do it.
return this.props.onClick(this.props.name);
}
【问题讨论】:
-
您应该能够使用输入 autoFocus 属性进行自动对焦。但是如果你有多个文本框并且在加载过程中都需要关注最后一个会赢
标签: javascript reactjs input react-redux