爲什麽提示target undefined啊

来源:3-4 React 表单

PLZY

2019-05-06 15:36

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>留言内容</label>

<input

type="text"

className="form-control"

placeholder="請輸入内容"

value={this.state.value}

onChange={() => this.handlechange()}

/>

</div>

<button type="submit" className="btn btn-primary">

留言

</button>

</form>

);

}

}

export default CommentBox;


写回答 关注

4回答

  • 环球学习机
    2020-02-10 12:20:17

    onChange={(event) => this.handlechange(event)},这个才对,上面有问题

  • 环球学习机
    2020-02-10 12:19:33

    onChange={() => this.handlechange(event)},你的上个人也是这个问题

  • feng2
    2019-05-30 00:16:48

    没有绑定到this实例, 可以这么写 onChange={ this.handlechange.bind(this)} 

  • 房自德
    2019-05-11 22:06:46

    onChange={ this.handlechange()}

基于实例的 React16 傻瓜课程

通过一系列简单有趣的例子,让你了解 React16 的基本概念和新特性

22325 学习 · 103 问题

查看课程

相似问题