我有两个文本字段id和用户名。下方是一个提交按钮。 单击提交按钮后,如何将用户名和ID传递给handleSubmit()?
Truth Table
condition1 condition2 AND OR
True True True True
True True True True
False True False True
True False False True
答案 0 :(得分:1)
该值应保存在组件状态并更新onChange
。调用handleSubmit
后,您将从状态中读取值。 const { name } = this.state
class form extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit() {
console.log(this.state.value)
}
render() {
.....
}
}