输入类型=“文本”默认值不能在reactjs中改变

Kar*_*yan 0 html reactjs

我有一个要求,我最初有一个 html 文本字段,它的默认值应为0. 但是,稍后我想更改文本框的值(在 ReactJS 中)。

我无法更改默认值。请找到我的 reactjs 代码。

<input name="discount" type="text" id="header_discount" step="0.01"  maxLength="5" min="0" max="100"  value={ this.state.item.discount ? this.state.item.discount : this.state.item.discount = "0" }  className="form-control" onChange={ this.handleInputChange } />  
Run Code Online (Sandbox Code Playgroud)

Tom*_*zyk 5

您可以使用默认值道具:

<input  defaultValue={0} name="discount" ...
Run Code Online (Sandbox Code Playgroud)