React 事件 监听
2017-05-22 13:58
302 查看
实例
同过 on + 驼峰事件名( 例如 onClick) 来添加时间绑定
React .获取render component 的组件的dom节点:
input 的数据获取
input的数据获取
监听change 事件 将数据绑定到 contentValue 上
组件的数据传递
var TestComponent= React.createClass({ getInitialState:function(){ return {contentValue:''} }, ContentHandler:function(event){ console.log(event); console.log(event.target.value) this.setState({contentValue:event.target.value}) }, render:function(){ return ( <div> <ul> <input type="text" ref="textInput" onChange={this.ContentHandler} /> <li>{this.state.contentValue}</li> <li>3</li> </ul> </div> ) } }) var Comp=React.createClass({ getInitialState:function(){ return { divStyle:{ fontSize:'12px', borderColor:'#0c9', borderStyle:'solid', borderWidth:'2px' }, count:0, } }, render:function(){ return <div ref="head" style={this.state.divStyle} className="wm-h">{this.props.name} <h1>我就试试{this.props.title}</h1> <button onClick={this.handleClick}>{this.state.count}</button> </div>; }, handleClick:function(event){ var d=this.refs.head; console.log(this.refs.head) d.style.background="#ccc"; this.setState(function(state){ return {count:state.count+1} }) } }); ReactDOM.render(<div> <Comp name="666" title="44944"/> <TestComponent></TestComponent> </div> , document.getElementById('app') );
同过 on + 驼峰事件名( 例如 onClick) 来添加时间绑定
<button onClick={this.handleClick}>{this.state.count}</button>
React .获取render component 的组件的dom节点:
使用 ref="nodeName"; 以 this.refs.nodeName 获取实例的DOM 节点
input 的数据获取
<input type="text" ref="textInput" onChange={this.ContentHandler} />
input的数据获取
ContentHandler:function(event){ this.setState({contentValue:event.target.value}) }
监听change 事件 将数据绑定到 contentValue 上
组件的数据传递
相关文章推荐
- 4、React对组件的DOM事件监听
- React监听窗口变化事件
- react addEventListener监听键盘事件实现扫码枪输入
- 夺命雷公狗-----React---13--事件监听
- React-Native - 使用AppState获取App运行状态(以及监听状态改变事件)
- react 监听 移动端 手机键盘 enter 事件
- iOS 原生模块 给 Javascript(ReactNative) 发送事件 (通知监听)
- ReactJS 监听页面滚动事件
- React Native - Keyboard API使用详解(监听处理键盘事件)
- react-native监听Android(Android向RN发送事件)
- js中的冒泡事件与事件监听
- Node.js自定义对象事件监听与发射
- Android截屏事件监听
- Android FragmentTabhost 监听tab点击事件
- 描述事件监听机制
- [wxWidgets]_[初级]_[监听wxListCtrl和wxGrid的滚动条事件]
- 按钮的监听事件在fragment中如何实现
- cookie用户自动登录和事件监听机制
- 监听按钮的点击事件