标签:one 方式 font style onchange get bin color system
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>
<button onClick={this.aaaa.bind(this)}>提交</button>
</div>
)
}
aaaa(){
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>
<button onClick={this.aaaa.bind(this)}>提交</button>
</div>
)
}
cccc(e){
this.setState({
acc:e.target.value
})
}
aaaa(){
console.log(this.state.acc)
}
}
标签:one 方式 font style onchange get bin color system
原文地址:https://www.cnblogs.com/tlfe/p/12603267.html