3 回答

TA貢獻1815條經驗 獲得超6個贊
問題是這一行:
this.handlePhoneNoChange?=?this.handlePhoneNoChange(this);
如果你仔細觀察,你就不見了.bind
。因此,您將其稱為this
事件。您的組件中沒有target
屬性,因此會引發錯誤。
錯誤的修復是:
this.handlePhoneNoChange?=?this.handlePhoneNoChange.bind(this);
但是,它不會解決其他答案中突出顯示的問題。

TA貢獻1875條經驗 獲得超5個贊
event.target.value基本上檢索調用它的任何輸入的值。
在這種情況下,可以通過 event.target.value 訪問telephoneno輸入的值
所以,使用事件的正確方法是,
handlePhoneNoChange(event) {
this.setState({ telephoneno: event.target.value });
}
你應該像這樣綁定它,
this.handlePhoneNoChange = this.handlePhoneNoChange.bind(this);
如果您可以在輸入的 onChange 事件中使用箭頭函數,那就更好了,
onChange={ (e) => this.handlePhoneNoChange(e) }

TA貢獻1799條經驗 獲得超9個贊
您沒有使用正確的方式在反應有狀態組件中使用狀態,在和函數props中用作參數constructorsuper
? constructor(props) {
? ? ? ? super(props);
? ? ? ? this.state = {
? ? ? ? ? ? name: '',
? ? ? ? ? ? address: '',
? ? ? ? ? ? city: '',
? ? ? ? ? ? telephoneno: '',
? ? ? ? ? ? stdcode: ''
? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? }
? }
并更新這一行:
this.setState({ telephoneno: event.target.value});
添加回答
舉報