I'm trying to get the "shown" month and year after hitting the "next" and "previous" links on the left and right of the date picker header.
Currently I'm using to get the month:
var selectedMonth = $('#calendar').datepicker('getDate').getMonth() + 1;
but it only returns the current month, not the shown month that comes with clicking "next" or "prev".
EDIT
I added the onChangeMonthYear
option with the datepicker in the function i have
function getDates() {
var selectedMonth = $('.ui-datepicker-month').text();
var selectedYear = $('.ui-datepicker-year').text();
}
still this just states the current date.
EDITED Again
the above worked just needed to set a delay :]
$.datepicker('getDate')
only returns the selected date of the datepicker, not the month that is currently being shown.
What you're looking for is to bind a function to onChangeMonthYear
. Docs here
Example:
$('#calendar').datepicker('option', 'onChangeMonthYear', function(year, month) { var selectedMonth = month })
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.