console
var MyComponent = React.createClass({
handleClick:function(event){
event.stopPropagation();
event.preventDefault();
var tipE = React.findDOMNode(this.refs.tip);
if(tipE.style.display === 'none'){
tipE.style.display === 'inline'
}else{
tipE.style.display === 'none'
}
},
render: function() {
return (
<div>
<button onClick = {this.handleClick}>显示|隐藏</button><span ref="tip">点击测试</span>
</div>
)
}
});
var InputComponent = React.createClass({
getInitialState:function(){
return {
inputContent:''
}
},
changeHander:function(event){
event.stopPropagation();
event.preventDefault();
this.setState({
inputContent:event.target.value
})
},
render:function(){
return (
<div>
<input type='text' onChange ={this.changeHander} /><span>{this.state.inputContent}</span>
</div>
)
}
})
React.render(
<div>
<MyComponent/>
<InputComponent />
</div>,document.getElementById('example')
)
<div id="example"></div>
div{
margin-bottom:30px;
}