當我在輸入上輸入時,他們不會使用我輸入的文本進行更新。如果我在所有表單上使用「this.state.value」,它們將使用相同的文本同時更新所有內容。HTML輸入未在句柄上更新
import React, { Component, PropTypes } from 'react';
import ReactDOM from 'react-dom';
export default class ContactArea extends React.Component {
constructor(props) {
super(props);
this.state = {
name: '',
email: '',
tel: '',
company: '',
msg: ''
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert(this.state.value);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<div class="row">
<div class="col-lg-6 form-group">
<label class="label-width">
Nome:
<input class="form-control" type="text" value={this.state.name} onChange={this.handleChange} />
</label>
</div>
<div class="col-lg-6 form-group">
<label class="label-width">
Email:
<input class="form-control" type="text" value={this.state.email} onChange={this.handleChange} />
</label>
</div>
<div class="col-lg-6 form-group">
<label class="label-width">
Telefone:
<input class="form-control" type="text" value={this.state.tel} onChange={this.handleChange} />
</label>
</div>
<div class="col-lg-6 form-group">
<label class="label-width">
Empresa:
<input class="form-control" type="text" value={this.state.company} onChange={this.handleChange} />
</label>
</div>
<div class="col-lg-12 form-group">
<label class="label-width">
Mensagem:
<textarea class="form-control" type="text" value={this.state.msg} onChange={this.handleChange} />
</label>
</div>
<div class="col-lg-12">
<input type="submit" value="submit" class="btn btn-primary button-width button-spacing" />
</div>
</div>
</form>
);
}
}