Reactjs 有条件地自动聚焦第一个输入
我通过在数组上映射来生成输入字段,但我只希望第一个输入自动聚焦Reactjs 有条件地自动聚焦第一个输入,reactjs,Reactjs,我通过在数组上映射来生成输入字段,但我只希望第一个输入自动聚焦 {keys.map((item, index) => { return ( <div className='poster--keys-values' key={index + 20}> <div className='poster--key-title' key={index + 10}>{item}</div>
{keys.map((item, index) => {
return (
<div className='poster--keys-values' key={index + 20}>
<div className='poster--key-title' key={index + 10}>{item}</div>
<input
{index === 1 ? 'autoFocus' : null} // <===== This isnt right
type='text'
id={item}
name={item}
key={index}
className='poster--value-title'
onChange={onChange}
/>
</div>
);
})}
{keys.map((项,索引)=>{
返回(
{item}
而不是
{index === 1 ? 'autoFocus' : null}
写:
autoFocus={index === 1}
应按预期工作:)而不是
{index === 1 ? 'autoFocus' : null}
写:
autoFocus={index === 1}
应按预期工作:)有自动对焦
属性,因此您可以执行以下操作:
...
<input
autoFocus={index === 0}
...
/>
。。。
有自动对焦
属性,因此您可以执行以下操作:
...
<input
autoFocus={index === 0}
...
/>
。。。