如何用值=“”正确填充输入?

时间:2019-05-27 16:13:05

标签: reactjs bootstrap-4

当我在输入中输入value =“”时,不允许我填写用户名和密码。

没有value =“”的情况下,我可以使用“ =“ =”的内容进行填充

{/* User */}
<div class="input-group form-group">
   <div class="input-group-prepend">
      <span class="input-group-text"><i class="fas fa-user"></i></span>
   </div>
   <input type="text" class="form-control" placeholder="username" value={this.state.name} onChange={this.handleChange}></input>
</div>
{/* Senha */}
<div class="input-group form-group">
   <div class="input-group-prepend">
      <span class="input-group-text"><i class="fas fa-key"></i></span>
   </div>
   <input type="password" class="form-control" placeholder="password" value={this.state.password} onChange={this.handleChange}></input>
</div>

输入字段必须允许我填写用户名和密码。

1 个答案:

答案 0 :(得分:0)

尝试使用“ defaultValue”代替“ value”,类似于: React Input Type not editable

{/* User */}
<div class="input-group form-group">
   <div class="input-group-prepend">
      <span class="input-group-text"><i class="fas fa-user"></i></span>
   </div>
   <input type="text" class="form-control" placeholder="username" defaultValue={this.state.name} onChange={this.handleChange}></input>
</div>
{/* Senha */}
<div class="input-group form-group">
   <div class="input-group-prepend">
      <span class="input-group-text"><i class="fas fa-key"></i></span>
   </div>
   <input type="password" class="form-control" placeholder="password" defaultValue={this.state.password} onChange={this.handleChange}></input>
</div>