• React 组件嵌套 父子关系


    代码实例;

    <!DOCTYPE html>
    <html lang="zh-cn">
    <head>
        <meta charset="UTF-8">
        <title>父子关系</title>
    </head>
    <body>
        <script src="./react-0.13.2/react-0.13.2/build/react.js"></script>
        <script src="./react-0.13.2/react-0.13.2/build/JSXTransformer.js"></script>
        <script type="text/jsx">
            var GenderSelect = React.createClass({
                render: function() {
                    return <select onChange={this.props.handleSelect}>
                    <option value="0">男</option>
                    <option value="1">女</option>
                    </select>
                }
            })
            var SignupForm = React.createClass({
                getInitialState: function() {
                    return {
                        name: '',
                        password: '',
                        gender: '',
                    }
                },
                handleChange: function(name, event) {
                    var newState = {}
                    newState[name] = event.target.value
                    this.setState(newState)
                },
                handleSelect: function(event) {
                    this.setState({gender: event.target.value})
                },
                render: function() {
                    console.log(this.state)
                    return <form>
                    <input type="text" placeholder="请输入用户名" onChange={this.handleChange.bind(this, 'name')} />
                    <input type="password" placeholder="请输入密码" onChange={this.handleChange.bind(this, 'password')} />
                    <GenderSelect handleSelect={this.handleSelect}></GenderSelect>
                    </form>
                }
            })
            React.render(<SignupForm></SignupForm>, document.body);
        </script>
    </body>
    </html>
    

      效果:

  • 相关阅读:
    常用css3属性
    jQuery瀑布流
    jQuery事件对象
    jQuery动画
    面向对象复习
    php 面向对象
    git
    存储数据
    ajax
    对象
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/7611875.html
Copyright © 2020-2023  润新知