reactjs - 无法在输入字段中输入
问题描述
我有以下代码:
constructor(props) {
super(props);
this.state = {
search: "",
value: "",
username:'',
email:'',
password: '',
};
this.onChange = this.onChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
...
...
onChange(e) {
this.setState(
{[e.target.name]: e.target.value})
}
...
...
<input type="password" placeholder="Password"
onChange={e => this.onChange(e)}
value={ this.state.password }
/>
但我无法输入密码字段。如果我删除该value={ this.state.password }
部分,然后我可以在该字段中输入,但是当该字段更改时,我的状态似乎没有更新。
问题是什么?
解决方案
您忘记为密码字段提供名称。它应该是
<input
type="password"
placeholder="Password"
name="password"
onChange={e => this.onChange(e)}
value={ this.state.password }
/>
推荐阅读
- json - 如何创建一个通用函数,将 json 字符串转换为 golang 中的结构?
- python - 将“import pandas”语句中的 DEBUG 警报静音
- angular - 有没有办法在表单中更改 formcontrolname(但保持相同的名称)?
- javascript - 我无法从我的 json 中收集数据 - React
- java - 当我运行我的程序时,JCheckBox 没有出现
- json - 是否可以在 jq 中的流上使用唯一运算符
- python-3.x - 用于 DNA 序列的 word2vec 程序中的代码错误
- pandas - 如何将 pandas DataFrame 的行全部绘制为线条?
- javascript - RegEx 用于在前瞻后匹配多个匹配项
- haskell - Lucid nav 元素给出关于属性列表的错误