Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 日期选择器e.target.value未定义_Javascript_Reactjs - Fatal编程技术网

Javascript 日期选择器e.target.value未定义

Javascript 日期选择器e.target.value未定义,javascript,reactjs,Javascript,Reactjs,我正在使用日历的Datepicker组件用用户选择的日期更新我的状态 当我试图使用输入-反应-输出错误更改默认日期时:“TypeError:e.target未定义” 多谢各位 声明: this.handleSubmit = this.handleSubmit.bind(this); this.handleDate = this.handleDate.bind(this); this.handleGuests = this.handleGuests.bind(this); this.handleN

我正在使用日历的Datepicker组件用用户选择的日期更新我的状态

当我试图使用输入-反应-输出错误更改默认日期时:“TypeError:e.target未定义”

多谢各位

声明:

this.handleSubmit = this.handleSubmit.bind(this);
this.handleDate = this.handleDate.bind(this);
this.handleGuests = this.handleGuests.bind(this);
this.handleName = this.handleName.bind(this);
this.state = {
  min: new Date().getHours,
  max: new Date(),
  booking: {
    date: new Date(),
    people: 1,
    name: 'John Doe',
  },
}
handleDate功能:

handleDate(e){
const booking = {...this.state.booking}
booking.date = e.target.value;
this.setState({booking});
}
日期选择器:

<DatePicker
            name="Datepicker"
            className="form-control mx-auto form-control-lg p-3"
            selected={this.state.booking.date}
            onChange={this.handleDate}
            showTimeSelect
            timeFormat="HH:mm"
            timeIntervals={60}               
            dateFormat="MMMM dd, yyyy h:mm aa"
            timeCaption="Time"
            placeholderText="Click and choose the date"
          />

来自自述文件日期选择器组件:

回调不使用事件,它已在handleChange函数的参数中包含date对象

handleChange(date) {
    this.setState({
      startDate: date
    });
  }

  render() {
    return (
      <DatePicker
        selected={this.state.startDate}
        onChange={this.handleChange}
      />
    );
  }
handleChange(日期){
这是我的国家({
开始日期:日期
});
}
render(){
返回(
);
}

试试这个:handleDate(dateValue){console.log(dateValue)}从e.target.value改为e,非常好用,谢谢@维顿,我试过这个,它对我有效,但我不明白为什么。你能解释一下原因吗?