如何使用 ReactJS 组件将自动对焦 HTML 属性包含到输入中?

我使用包含自动对焦输入的 React 元素进行了尝试

<input className='EI-input' autoFocus='true' tabIndex='0'
                               name='username' type='text'
                               ref='inputUser' autoComplete='on'
                               placeholder='email' />

但是当呈现为静态标记时,我没有看到浏览器中呈现的自动对焦属性(使用 Chrome 和 FireFox 中的 devTools 检查)
const jsx = React.renderToStaticMarkup(<InputWithAutoFocus />);
console.log(jsx); // I don't see the autofocus attribute in the input

我也尝试过只使用 autoFocus 和 autoFocus='on' 和自动对焦。这些似乎都不起作用。

根据 ReactJS docs , autoFocus 应该可以工作。

最佳答案

由于不同浏览器的解释,这是不支持的:



查看完整的线程 here

10-08 12:06