0

我正在使用此代码从 bootstrap-datepicker 获取日期。我发现了几个问题与同一问题有关,但似乎没有一个对我有用。我不确定我错过了什么。

<div id="dateCal"></div>

这是我的 jQuery

$input = $("#dateCal");

$input.datepicker({
        format: 'dd-mm-yyyy'
    })
    .on('changeDate', function(e){
        console.log(e.date);
    });

mu 控制台输出如下所示:

Sat Jun 21 2014 00:00:00 GMT-0400 (EDT) 

我究竟做错了什么?在设置格式选项时,我需要 e.date 出来。

4

1 回答 1

1

When processing events in javascript (and jQuery or bootstrap), the "e" passed to the function is the event object. Reading e.date could refer to the datetime of the event. You want to be reading this.value, where this refers to the HTML element associated with the event, or in this case, your date field.

Do instead:

  console.log(this.value);
于 2014-06-26T22:03:05.733 回答