随笔 - 83  文章 - 1  评论 - 2  阅读 - 40024

React实例6-显示隐藏

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>test01</title>
<script src="build/browser.min.js"></script>
<script src="build/react.js"></script>
<script src="build/react-dom.js"></script>
<style media="screen">
.box{ width:200px;
height: 300px;
background: gray;}
</style>
<script type="text/babel">
class ShowHide extends React.Component{
constructor(...args){
super(...args);
this.state={display:'block'};
}

fn(){
this.setState({display:this.state.display=='block'?'none':'block'
});
}

render(){
return <div>
<input type="button" value="显示/隐藏" onClick={this.fn.bind(this)}/>
<div className="box" style={{display:this.state.display}}>
</div>
</div>
}
}

window.onload=function(){
ReactDOM.render(
<ShowHide/>,
document.getElementById('app'),function(){
console.log("渲染成功啦")
}
);
}
</script>
</head>

<body>
<div id="app"></div>


</body>
</html>

posted on   代码笔  阅读(196)  评论(0编辑  收藏  举报
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示