React 父组件如何获取子组件的ref值?
父组件:
const registerStepTwo = React.createClass({ handleChange:function(){ var confirmPassText = this.refs.confirmPassText.value; console.log(confirmPassText)//子组件ref的值取不到 }, render(){ return( <div> {navBar} <div className="list-ul"> <ul> <ConfirmPass ref="confirmPassText" onChange={this.props.handleChange} /> </ul> </div> </div> ) } })
子组件:
const ConfirmPass = React.createClass({ render(){ return( <div> <li> <div className="registerLeft"> <input ref="confirmPassText" type="password" onChange={this.handleChange} className="loginText" /> </div> </li> </div> ) } })
茅侃侃
相关分类