react.js 测试

React组件实例

<html>
    <head>
        <title>hellow</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
        <meta charset="utf-8"  />
    </head>
    <body>
        <div id="root">

        </div>

        <script type="text/jsx">
        //创建组建
        var TestButtonComponent = React.createClass({
            handleClick:function(event){
                var tipsE = React.findDOMNode(this.refs.tips);
                if(tipsE.style.display === 'none'){
                    tipsE.style.display = 'inline';
                }else{
                    tipsE.style.display = 'none';
                }
                event.stopPropagation();    //阻止事件冒泡
                event.preventDefault();     //阻止默认事件
            },
            render:function(){
                return (
                        <div>
                            <button onClick={this.handleClick}>显示|隐藏</button><span ref="tips">测试button</span>
                        </div>);
            }
        });

        var TestInputComponent = React.createClass({
            getInitialState:function(){
                return {
                    inputContent:'ii'
                };
            },
            handleChange:function(event){
                this.setState({
                    inputContent:event.target.value
                });
            },
            render:function(){
                return (
                    <div>
                        <input type="text" onChange={this.handleChange} /> <span>{this.state.inputContent}</span>
                    </div>
                );
            }
        });

        //调用组建
        React.render(
            <div>
                <TestButtonComponent />
                <br/> <br/>
                <br/>
                <TestInputComponent />
            </div>,
            document.getElementById('root')
        );

        </script>
    </body>

<html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值