zoukankan      html  css  js  c++  java
  • 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>
    

      效果:

  • 相关阅读:
    3139:[HNOI2013]比赛
    3143: [Hnoi2013]游走
    目前游戏行业内部主要几款游戏引擎的技术对比
    6.使用AngularJS模板来创建视图
    css选择器(E[att^=”val”]序号选择器)
    5.把作用域实现为数据模型
    4.了解AngularJS模块和依赖注入
    3.创建基本的AngularJS应用
    2.AngularJS MVC
    1.AngularJS初探
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/7611875.html
Copyright © 2011-2022 走看看