1、问题背景
利用React获取DOM节点,需要利用ref属性
2、实现源码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>React获取DOM节点</title>
<script type="text/javascript" src="../js/react.js" ></script>
<script type="text/javascript" src="../js/react-dom.js" ></script>
<script type="text/javascript" src="../js/browser.min.js" ></script>
<script type="text/babel">
var Cat = React.createClass({
cutClick:function(){
this.refs.person.focus();
},
render:function(){
return (
<div>
<input type="text" ref="person" />
<input type="button" value="查询" οnclick="{this.cutClick}" />
</div>
)
}
});
ReactDOM.render(
<Cat />,
document.getElementById("catQuery")
);
</script>
</head>
<body>
<div id="catQuery"></div>
</body>
</html>
3、实现结果