首页 > 其他 > 详细

react 获取input的值 ref 和 this.setState({})

时间:2020-02-01 17:55:20      阅读:386      评论:0      收藏:0      [点我收藏+]
1、ref
  //class
  my_filter(reg){
          const inpVal = this.input.value;
          console.log(inpVal);
     console.log(reg);

      };
 
  //render
  <input  type="text" ref={input => this.input = input}  defaultValue = ‘helloworld!‘ />
  <button onClick = {this.my_filter.bind(this, reg)}> 确定 </button>
 
 
2、this.setState({})

  //class

  this.state = {

    inpVal : ‘helloworld‘

  };

  

  my_filter(e){
          this.setState({ inpValu:e.target.value })
     };
 

  //render

  <input  type="text"  onChange={this.my_filter.bind(this)} defaultValue={this.state.inpValu}/>

 

react 获取input的值 ref 和 this.setState({})

原文:https://www.cnblogs.com/alchemist-z/p/12249003.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!