如果在标签“Tipo consenso”中我选择选项“Leggi Referto”,我希望显示“Codice Referto”字段,否则我不希望显示它。
Form onSubmit={this.handleSubmit}>
<div className="form-section">
<Label for="type" text="Tipo consenso" />
<select
name="rights"
value={this.state.rights}
onChange={this.handleInputChange}>
<option default value="vuoto"></option>
<option value="Carica Referto">Carica Referto</option>
<option value="Leggi Referto">Leggi Referto</option>
</select>
<Label text="Codice Referto" />
<input
onVisible={this.checkVisibility}
type="text"
name="codiceReferto"
placeholder="Inserire hash referto"
autoFocus
onKeyPress={this.onEnter} //allows you to move to the next panel with the enter key
value={this.state.codiceReferto}
onChange={this.handleInputChange}
/>
最佳答案
尝试下面的代码希望它能帮助你
{
this.state.rights === 'Leggi Referto' ?
<div>
<Label text="Codice Referto" />
<input
onVisible={this.checkVisibility}
type="text"
name="codiceReferto"
placeholder="Inserire hash referto"
autoFocus
onKeyPress={this.onEnter} //allows you to move to the next panel with the enter key
value={this.state.codiceReferto}
onChange={this.handleInputChange}
/>
</div> : null
}
关于javascript - 如何根据选择使新字段出现在表单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57630226/