显示隐藏功能
我要实现的功能:
1.点击关闭按钮时 隐藏 标签的内容
2.点击ON按钮时 实现显示标签的内容
render里面要包含
<div>
<div>
<span></span>
<div>
<button></button>
<div>
实现代码如下:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import Greeting from './Greeting';
import registerServiceWorker from './registerServiceWorker';
class LoginControl extends React.Component {
constructor(props) {
super(props)
this.state={clickOn:false}
this.handleClick = this.handleClick.bind(this)
//this.handleShow = this.handleShow.bind(this)
}
handleClick(e) {
this.setState(({clickOn:!this.state.clickOn}))
}
render() {
let style = {display :this.state.clickOn ? 'none' : 'block' }
/* if(this.state.clickOn){
style={display: 'none'}
}else {
style={display: 'block'}
}*/
return (
<div>
<div style={style}>
<span>显示!</span>
</div>
<button onClick={this.handleClick}>{this.state.clickOn ? 'ON' : 'OFF'}</button>
</div>
);
}
}
ReactDOM.render(
<LoginControl />,
document.getElementById('root')
);