zoukankan      html  css  js  c++  java
  • react 获取input的值 ref 和 this.setState({})

    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}/>

     
  • 相关阅读:
    jqurey技术总结
    ie浏览器兼容问题小结
    FIS的合并压缩技术
    对js中数组的一些总结
    浅谈如何面向对象进行封装
    13th week blog
    12th week blog
    11th week blog
    10th week blog
    9th Week blog
  • 原文地址:https://www.cnblogs.com/alchemist-z/p/12249003.html
Copyright © 2011-2022 走看看