我试图检索我的复选框的检查值,但我得到空值这是我的代码
<form onSubmit={this.onSubmit}>
<fieldset>
<legend>RFX/RFP:</legend>
<div className="form-check">
<input type="checkbox" className="form-check-input" onChange={this.onChange} value={this.state.rfx} name="rfx" id="rfx" />
<label className="form-check-label" name="rfx">RFX</label>
<input type="checkbox" className="form-check-input" onChange={this.onChange} value={this.state.rfp} name="rfp" id="rfp" />
<label className="form-check-label" >RFP</label>
<input type="checkbox" className="form-check-input" onChange={this.onChange} value={this.state.rfp_x} name="rfp(x)" id="rfp(x)"/>
<label className="form-check-label" >RFP(X)</label>
<input type="checkbox" className="form-check-input" onChange={this.onChange}name="all" id="all" />
<label className="form-check-label" name="all" id="all">ALL</label>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
和我的方法:
constructor(props){
super(props)
this.state={
rfp:"",
rfx:"",
rfp_x:"",
all:"",
}
this.onChange = this.onChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
onChange(e){ …Run Code Online (Sandbox Code Playgroud)