我跟着这个documentation并创建了一个带有反应的选择标签。
我编辑了这个问题,如果我使用className =“浏览器默认”选择它工作正常。但为了实现,请选择它不起作用。
onChange事件不适用于我的情况。该函数不会被调用。我的onChange不能与反应一起工作
import React from 'react';
class Upload extends React.Component{
constructor(props){
super(props);
this.state={
degree:''
}
this.upload=this.upload.bind(this);
this.degreeChange=this.degreeChange.bind(this);
}
componentDidMount() {
$('select').material_select();
}
degreeChange(event){
this.setState({degree:event.target.value});
console.log(this.state.degree);
}
upload(){
alert(this.state.degree);
}
render() {
return (
<div className="container">
<form onSubmit={this.upload}>
<div className="input-field col s4">
<select value={this.state.degree} onChange={this.degreeChange}>
<option value="" disabled>Choose Degree</option>
<option value="B.E">B.E</option>
<option value="B.Tech">B.Tech</option>
</select>
</div>
<div className="row center-align">
<input className="waves-effect waves-light btn centre-align" type="submit" value="Submit"/>
</div>
</form>
</div>
);
}
}
我在这里没有得到任何错误,但我的degreeChange函数没有被调用。我没有得到我的错误。
[使用阵营JS为下拉OnChange事件]的可能的复制(http://stackoverflow.com/questions/28868071/onchange-event-using-react-js-for-drop-down) –
@JohnRuddell,我认为这个问题不是你粘贴的链接的重复,这与** setState **的异步性质有关,这没有任何'onChange'问题。 –
[如何从选定的下拉列表中获取最新值]可能的重复(http://stackoverflow.com/questions/39506293/how-to-get-the-latest-value-from-selected-drop-down) –