最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery datepicker get month and year shown not current - Stack Overflow

programmeradmin0浏览0评论

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 es 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 :]

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 es 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 :]

Share Improve this question edited Feb 23, 2013 at 21:55 Matt asked Feb 23, 2013 at 19:29 MattMatt 1051 gold badge1 silver badge8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

$.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 })
发布评论

评论列表(0)

  1. 暂无评论