【发布时间】:2017-10-01 07:27:09
【问题描述】:
我正在构建一个非常基本的 React 应用程序,但在表单输入方面存在一些问题: 我的状态:
class App extends Component {
constructor(){
super();
this.state = {
books: [],
book:{
author:"",
title: ""
}
}
this.handleInputChange = this.handleInputChange.bind(this)
}
我的表格:
<form onSubmit={this.addBook}>
<input
name="author"
type="text"
placeholder="author"
value={this.state.book.author}
onChange={this.handleInputChange}
/><br/>
<input
name="title"
type="text"
placeholder="title"
value={this.state.book.title}
onChange={this.handleInputChange}
/><br/>
<input type="submit" />
<button>Update</button>
<button>Delete</button>
</form>
我的事件处理程序:
handleInputChange(event) {
this.setState({
[event.target.name]: event.target.value
});
}
我仍然无法在输入字段中输入数字。当我尝试对一个值进行数字化时,没有任何反应,并且输入字段没有正确更新。有什么建议么? 谢谢
【问题讨论】:
-
handleInputChange或addBook哪个部分不能正常工作? -
handleInputChange
标签: javascript reactjs