react为我们提供了两种获取value的方法
第一种:非受控方法获取
import React,{Component} from 'react' export default class system extends Component{ constructor(props){ super(props) this.state = { acc:'' } } render(){ return ( <div>
<input ref="ss"></input> //input输入框
<button onClick={this.aaaa.bind(this)}>提交</button> //点击获取input输入框的内容
</div> ) } aaaa(){
//拿到input输入框的value的值 console.log(this.refs.ss.value) } }
第二种:受控方式获取
import React,{Component} from 'react'
export default class system extends Component{
constructor(props){
super(props)
this.state = {
acc:''
}
}
render(){
return (
<div>
<input value={this.state.acc} onChange={this.cccc.bind(this)}></input> //input输入框
<button onClick={this.aaaa.bind(this)}>提交</button> //点击获取inoput框的内容
</div>
)
}
cccc(e){
this.setState({
acc:e.target.value
})
}
aaaa(){
console.log(this.state.acc)
}
}