直接上代码
constructor(props){
super(props);
this.state = {
username: '',
password: ''
}
this.onInputChange = this.onInputChange.bind(this);
}
render(){
let { username, password } = this.state;
return (
<Fragment>
<input type="text" name="username" value={username} onChange = { this.onInputChange } />
<input type="text" name="username" value={password} onChange = { this.onInputChange } />
</Fragment>
)
}
onInputChange (e){
let InputName = e.target.name;
let InputValue = e.target.value;
this.setState({
[ InputName ]: InputValue ,
})
}