在react中获取真实dom的时候就需要用到ref属性,具体使用如下

var MyComponent = React.createClass({
  handleClick: function() {
    console.log(this.input)
  },
  render: function() {
    return (
      <div>
        <input type="text" ref={(input) => {this.input = input}} />
        <input type="button" value="Focus the text input" onClick={this.handleClick} />
      </div>
    );
  }
});

ReactDOM.render(
  <MyComponent />,
  document.getElementById('example')
);

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-15
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案