爲什麼提示target undefined啊
import React from "react";
class CommentBox extends React.Component {
constructor(props) {
super(props);
this.state = {
value: ""
};
}
handlechange(event) {
this.setState({ value: event.target.value })
}
handlesubmit(event) {
alert(this.state.value)
event.preventDefault()
}
render() {
return (
<form className="p-5" onSubmit={() => this.handlesubmit()}>
<div className="formgroup">
<label>留言內(nèi)容</label>
<input
type="text"
className="form-control"
placeholder="請輸入內(nèi)容"
value={this.state.value}
onChange={() => this.handlechange()}
/>
</div>
<button type="submit" className="btn btn-primary">
留言
</button>
</form>
);
}
}
export default CommentBox;
2020-02-10
onChange={(event) => this.handlechange(event)},這個才對,上面有問題
2020-02-10
onChange={() => this.handlechange(event)},你的上個人也是這個問題
2019-05-30
沒有綁定到this實例, 可以這么寫 onChange={ this.handlechange.bind(this)}?
2019-05-11
onChange={ this.handlechange()}