Des*_*ley 1 html autofocus reactjs
当我在我从React类返回的输入上设置autofocus属性时,会产生以下错误:
error TS2339: Property 'autofocus' does not exist on type 'HTMLAttributes'
Run Code Online (Sandbox Code Playgroud)
这是令人反感的代码:
return <input type="text" onChange={this.handleChange} value={this.state.text} autofocus/>;
Run Code Online (Sandbox Code Playgroud)
我尝试了更详细autofocus="autofocus",没有运气。
可以使用react和html完成吗?我可以用javascript设置它,但如果有的话,我宁愿使用html解决方案。
(编辑)正如Dominic Tobias所指出的,autoFocus(区分大小写)本身就可以解决问题,如果尝试这样设置属性autoFocus="autofocus",则会收到错误消息:
TS2322 Type 'string' is not assignable to type 'boolean'.
Run Code Online (Sandbox Code Playgroud)
反应骆驼案例属性。使用:
<input type="text" onChange={this.handleChange} value={this.state.text} autoFocus />;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1047 次 |
| 最近记录: |