可以这么写吧!


  • 0

    回复: #9 百分比换算器
    class Input extends React.Component {
    constructor(props) {
    super(props)
    this.state = {
    number: 0
    }
    }
    handleChange(e) {
    this.setState({
    number: e.target.value
    })
    }
    render() {
    return (
    <div>
    <input onChange={this.handleChange.bind(this)} />
    <PercentageShower showPercent={this.state.number}/>
    </div>
    )
    }
    }

    class PercentageShow extends React.Component {
    render() {
    return (
    <div>
    {Number(this.props.showPercent).toFixed(2)}%
    </div>
    )
    }
    }
    class PercentageApp extends React.Component {
    constructor(props) {
    super(props)
    this.state = {

    }
    

    }
    render() {
    return (
    <div style={{
    position: 'absolute',
    left: 400,
    top: 100
    }}>
    <Input />

      </div>
    )
    

    }


登录后回复
 

与 ScriptOJ 的连接断开,我们正在尝试重连,请耐心等待