Home  >  Article  >  Web Front-end  >  Use react.js to get real DOM nodes

Use react.js to get real DOM nodes

零下一度
零下一度Original
2017-04-17 14:45:551545browse

The following editor will bring you an article about getting real DOM nodes in react.js. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look.

In order to obtain the real DOM node, the text input box must have a ref attribute, and then this.refs.[refName] will return the real DOM node.

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

ReactDOM.render(
 <MyComponent />,
 document.getElementById(&#39;example&#39;)
);

The above is the detailed content of Use react.js to get real DOM nodes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn