0

我用这个生成器创建了一个引导日期选择器。你可以在这里看到结果。文档说,很容易得到日期

$('#datepicker').datepicker('getDates');

他们也说:

返回本地化日期对象列表,表示选择中第一个日期选择器的内部日期对象。用于多日期选择器。

不幸的是,这在我上面的示例中不起作用。如果我在选择日期后单击按钮,我只会得到一个 jQuery 对象,而不是日期列表。

我究竟做错了什么?

4

1 回答 1

2

I've had the same issue. The problem is that you're not using a multidate picker, but a range picker. The current datepicker does not have a method to get the dates from all pickers.

That's not a big problem, since each date can be easily obtained by using another function: getDate

I've made a jsfiddle to get the dates and count the number of days between two dates. You can see the full example here: http://jsfiddle.net/svierkant/7abqJ/1/

$(document).ready(function()
{
    $("#datepicker").datepicker({
        format: "dd.mm.yyyy",
        multidate: true,
        calendarWeeks: true,
        autoclose: true,
        todayHighlight: true,
        startDate : new Date("2014-02-01"),
        endDate : new Date()
    }).on("changeDate", function(e){
        $begin = $('#start').datepicker('getDate');
        $end = $('#end').datepicker('getDate');
    });
});
于 2014-04-11T15:33:51.117 回答