<!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{ 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>