简体   繁体   中英

getdates() in bootstrap-datepicker does not work

I created a bootstrap-datepicker with this generator . You can see the result here . The docs are saying , that it's easy to get the dates with

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

They say as well:

Returns a list of localized date objects representing the internal date objects of the first datepicker in the selection. For use with multidate pickers.

Unfortunatley, this does not work in my example above. If I click on the button after I choose the dates, I just get an jQuery object, not a list of dates.

What am I doing wrong?

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');
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM