简体   繁体   中英

JQuery Datepicker date is captured only when the day is clicked

Ran into a weird problem with jQuery Datepicker. I've set the option changeMonth: true to enable month change.

Say, if my datepicker displays a date 02/05/2013 and when I just change the month to April(not clicking on any day in the control), the date gets displayed as 02/04/2013 . But when I get the date from the control, I end up getting the old month value instead of the newly selected one.

code:

$('#uxStartDateTime').datetimepicker({
    timeFormat: "hh:mm tt",
    dateFormat: "dd/mm/yy",
    showButtonPanel: false,
    changeMonth: true,
    changeYear: true
});

//getting the date
var startDate = $('#uxStartDateTime').datetimepicker('getDate');

//formatting this date to it send via ajax to c#
startDate = startDate.getFullYear() + "-" + (startDate.getMonth() + 1) + "-" + startDate.getDate() + " " + startDate.getHours() + ":" + startDate.getMinutes();

Is there anything wrong with my method or is this a known issue?

That is the expected datepicker behavior, as adeneo pointed out in his comment. If you want to change this, you will have to write a method that is fired on change of month.

$('.ui-datepicker-month').change(function () {
    // if there is a value in your controller, change it
});

I'll leave the actual logic of adding/subtracting months to a date to you.

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