我試圖從文本區域輸入一次,然後輸入完成。我在某處讀到你需要onBlur事件處理程序來實現這個功能,而不是onChange。但是,當我使用onBlur時,我無法輸入我的輸入。我哪裏錯了?如何在反應中從文本區域讀取我的輸入?
import React from 'react'
import ReactDOM from 'react-dom'
class HelloWorld extends React.Component{
constructor(props) {
super(props)
this.state = {
value: '',
}
}
handleChange(event) {
this.setState({value: event.target.value})
console.log(this.state.value)
}
render(){
return(
<div>
<h1>Hello World Restaurant</h1>
<textarea placeholder="Enter name of guest:" onBlur={this.handleChange.bind(this)} value={this.state.value}></textarea>
</div>
)
}
}
ReactDOM.render(<HelloWorld/>,document.getElementById('root'))
有你啦閱讀文檔? https://facebook.github.io/react/docs/forms.html –
@mike是的我已閱讀文檔。 –