为了获取真实的dom节点,文本输入框必须有一个 ref 属性,然后 this.refs.[refname] 就会返回这个真实的 dom 节点。
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('example') );
以上就是用react.js来获取真实的dom节点的详细内容。