【问题标题】:How to autofocus react textarea?如何自动对焦反应textarea?
【发布时间】:2016-10-01 13:47:45
【问题描述】:

我已经尝试过 autoFocus 或 focus(),但似乎不起作用。

<textarea autoFocus />

or

<textarea ref="textarea" />
componentDidMount() {
  findDOMNode(this.refs.textarea).focus();
}

编辑

autoFocus 似乎可以在 chrome 中使用。

autoFocusfoucs() 在 iOS 中都不起作用。

【问题讨论】:

  • &lt;textarea autofocus&gt;&lt;/textarea&gt; 在 Chrome 中对我不起作用。自动对焦字段不会在 html 中呈现。

标签: reactjs textarea


【解决方案1】:

componentDidMount 中调用focus() 似乎可以在桌面版Chrome 和Firefox 中使用。

Demo.

似乎Mobile Safari intentionally suppresses auto-focussing 的元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多