html:
<!DOCTYPE html>
<html>
<head>
<Meta charset='utf-8' />
<script src="https://fb.me/react-0.13.3.js"></script>
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
</head>
<body>
<div id="hello"></div>
<script type="text/jsx"> var SexButton = React.createClass({ getInitialState: function() { return {sex: 'male'}; },handleClick: function(event) { this.setState({sex: this.state.sex === 'male' ? 'female' : 'male'}); },render: function() { var text = this.state.sex === 'male' ? '小伙儿' : '姑娘'; return ( <p onClick={this.handleClick}> 你是 [{text}] ,点击变性 </p> ); } }); React.render( <SexButton />,document.getElementById('hello') ); </script>
</body>
</html>
利用状态机可以实现美好的富交互,想想就怕