React(0.13) checked 구성 요소 정의

3164 단어
<!DOCTYPE html>
<html>
    <head>
        <title>React JS</title>
        <script src="../build_0.13/react.js"></script>
        <script src="../build_0.13/JSXTransformer.js"></script>
    </head>
    <body>
        <div id="example">
        
        </div>
        
        <script type="text/jsx">
            var Checked = React.createClass({
                    // 
                    getInitialState:function(){
                        return {checked:true};
                    },
                    // 
                    handleChange:function(event){
                        this.setState({checked:event.target.checked});
                    },
                    // 
                    submitHandler:function(event){
                        event.preventDefault();
                        alert(this.state.checked);
                    },
                    // html
                    render:function(){
                        return (
                            <form onSubmit={this.submitHandler} >
                                <input type="checkbox" value="A" checked={this.state.checked} onChange={this.handleChange} />
                                <br/>
                                <button type="submit">speak</button>
                            </form>
                        );
                    }
                });

            // 
            React.render( <Checked />, document.getElementById('example') );
        </script>
    </body>
</html>

좋은 웹페이지 즐겨찾기