<script type="text/babel">
var Myelement=React.createClass({
handleClick:function(){
this.refs.myInput.focus(); this.refs.[refname]获取真实的节点 只有真实的DOM发生click事件之后 才会发生this.refs.myInput
},
render:function(){
return (
<div>
<input type="text" ref="myInput" />
<input type="button" value="focus" onclick={this.handleClick} />
</div>
);
}
});
ReactDOM.render(
<Myelement/>,
document.getElementById(‘example‘)
);
</script>
时间: 2024-10-10 17:13:44