【发布时间】:2021-08-03 04:42:24
【问题描述】:
我目前正在使用带有 .tsx 文件的 Ionic React。当我做一个简单的document.getElementById("input-id").value 时,得到了错误Property 'value' does not exist on type 'HTMLElement'。寻找解决这个问题的方法,找到打字稿解析器<HTMLInputElement>,但由于 HTMLElement 没有很多 HTMLInputElement 道具,所以不起作用。
在这种情况下如何获取输入的值?
我的代码在这里。由于 Typescript 错误,它甚至无法编译:
handleChange() {
const input = document.getElementById("id").value;
}
render() {
return (
<IonPage>
<IonContent fullscreen>
<TextField
id="id"
label="Input"
variant="outlined"
required
/>
</IonContent>
</IonPage>
);
}
【问题讨论】:
标签: reactjs typescript ionic5 tsx