1 Star 0 Fork 0

Hanley / study-front

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
47th.html 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
hanley 提交于 2018-07-31 22:35 . react 组件+脚手架
<!DOCTYPE html>
<html>
<head>
<title>react-ref</title>
<meta charset="UTF-8" />
<script src='../node_modules/react/umd/react.development.js'></script>
<script src='../node_modules/react-dom/umd/react-dom.development.js'></script>
<script src='../node_modules/babel-standalone/babel.min.js'></script>
<!--
ref 类似原生dom操作
-->
</head>
<body>
<div id="my"></div>
<script type="text/babel">
class Hello extends React.Component{
constructor(){
super();
this.state = {
value:'abc'
};
};
handleChange(e){
this.setState({
value:e.target.value
})
};
changeFocus(){
this.refs.myText.focus();
this.refs.myH.innerText='12345';
};
render(){
return (
<div>
<p>
<input type="text" ref="myText"/>
</p>
<h1 ref="myH"></h1>
<button onClick={()=>this.changeFocus()}>click</button>
<p>
<input type="text" value={this.state.value}
onChange={(e)=>this.handleChange(e)}/>
<span>{this.state.value}</span>
</p>
</div>
)
}
};
ReactDOM.render(
<Hello/>,
document.getElementById('my')
)
</script>
</body>
</html>
1
https://gitee.com/thanlin/study.git
git@gitee.com:thanlin/study.git
thanlin
study
study-front
master

搜索帮助