如何使用React js传递有关提交的用户详细信息

时间:2018-10-19 15:05:40

标签: reactjs button

我有两个文本字段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

1 个答案:

答案 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() {
       .....
     }
 }