我正在 React JS 上尝试一个简单的程序,代码如下
class Employee extends Component {
constructor() {
super();
this.state = {
name: '',
address: '',
city: '',
telephoneno: '',
stdcode: ''
}
// Other event handlers goes here
this.handlePhoneNoChange = this.handlePhoneNoChange(this);
}
handlePhoneNoChange(event) {
this.setState({ telephoneno: event.target.telephoneno });
}
render() {
return (
<center>
<div>
<div class="input-group input-group-sm w-50">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Phone No</span>
</div>
<input type="text" class="form-control" placeholder="Phone No" id="phoneno" aria-label="PhoneNo" aria-describedby="basic-addon1" onChange={ this.handlePhoneNoChange } value={ this.state.telephoneno } /><br/>
</div><br/>
</div>
</center>
);
}
}
export default Employee;
它与'TypeError: Cannot read property 'telephoneno'未定义的错误。
我试图在这里理解这个概念。
为什么它只报告“telephoneno”错误而不报告其他字段?我究竟做错了什么 ?
红糖糍粑
慕田峪4524236
扬帆大鱼
相关分类