getInitialState:function(){ return {
password:'',
trueName:'',
idcard:'',
reidcard:''
}
},
onPassChange:function(e){ this.setState({password:e.target.value})
},
onTrueNameChange:function(e){ this.setState({trueName:e.target.value})
},
onIdcardChange:function(e){ this.setState({idcard:e.target.value})
},
onReidcardChange:function(e){ this.setState({reidcard:e.target.value})
},上面这段代码是对四个文本框的value的操作,怎么把这四个方法用一个方法来封装呢
1 回答

翻阅古今
TA贡献1780条经验 获得超5个赞
onChange: function(field) { return function(e) { this.setState({[field]: e.target.value}) } }
使用:
<input type="password" onChange={this.onChange('password')} />
添加回答
举报
0/150
提交
取消