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

     
  • 相关阅读:
    内存分布
    多态的作用
    c++虚函数实现与this指针
    Makefile 初探
    编译性语言和解释性语言
    从今天开始学好C++
    Java基础
    程序流程控制
    Java运算符
    初识Java
  • 原文地址:https://www.cnblogs.com/alchemist-z/p/12249003.html
Copyright © 2011-2022 走看看