嗨,我正在使用带有负值和正值的反应多选。当我选择 -1 时,它会自动更改为 1。所以无法选择 -1。其他值工作正常。
class FlavorForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: '1'};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert('Your favorite flavor is: ' + this.state.value);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Pick your favorite flavor:
<select value={this.state.value} onChange={this.handleChange} multiple>
<option value="-1">Grapefruit</option>
<option value="0">Lime</option>
<option value="1">Coconut</option>
<option value="2">Mango</option>
</select>
</label>
<input type="submit" value="Submit" />
</form>
);
}
}
ReactDOM.render(
<FlavorForm />,
document.getElementById('root')
);
请帮助如何通过反应多选选择-1。