react多个input框取值技巧

直接上代码

constructor(props){
   super(props);
   this.state = {
       username: '',
       password: ''
   }
   this.onInputChange = this.onInputChange.bind(this);
}

render(){
   let { username, password } = this.state;
   return (
         
             
             
         
   )
}

onInputChange (e){
   let InputName = e.target.name;
   let InputValue = e.target.value;
   this.setState({
       [ InputName ]: InputValue ,
   })
}

你可能感兴趣的:(react多个input框取值技巧)