标签:
降低页面从服务器和用户输入得到数据,来展示页面的过程的复杂性。
<style>.alert-text{color:red;}</style><script type="text/jsx">var Hello = React.createClass({render:function() {return <div className="alert-text">Hello {this.props.name} </div>;//{xxx}表示执行javascript表达式xxx}});React.render(<Hello name="World")/>,document.getElementById(‘container‘));</script>
style="color:red"//在组件的属性里这样会报错,不再使用字符串的方式,而是使用对象,对象的每个键用驼峰命名styleObje = {color:"red",fontSize:"44px"};var Hello = React.createClass({render:function() {return <div style ={styleObj} >Hello {this.props.name} </div>;//{xxx}表示执行javascript表达式xxx}});
状态说明:
props和state的对比、相关性
命名方式:(类似onClick的驼峰命名,区别于原生html的全小写) 用props的方式存自身函数
1. 回调函数中:获取到子组件的DOM(需要使用ref属性),操作DOM
var TestClickComponent = React.createClas({handleClicik:function(e){var tipE = React.findDOMNode(this.refs.tip);if(tipE.style.display === "none"){tipE.style.display ="inline";}else{tipE.style.display ="none";}e.stopPropagation();e.preventDefault();}render:function(){return (<div><button onClick={this.}>显示|隐藏</button> <span ref="tip">测试点击</span></div>);}});
var TestInputComponent = React.createClass({
getInitialState:function() {
return {
inputContent:‘‘
};
},
changeHandler:function(e){
this.setState({
inputContent:e.target.value
});
e.preventDefault();
e.stopPropagation();
}
render:function(){
return (
<div>
<input type="text" onChange={this.changeHandler}/><span>{this.state.inputContent}</span>
</div>
);
}
}); 标签:
原文地址:http://www.cnblogs.com/laiqun/p/5558608.html