jQuery datepicker得到的月份和年份不是最新的 [英] jQuery datepicker get month and year shown not current

查看:67
本文介绍了jQuery datepicker得到的月份和年份不是最新的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想点击日期选择器标题左侧和右侧的下一个和上一个链接后显示显示的月份和年份。

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;

但它只返回当前月份,而不是单击下一步或 prev。

but it only returns the current month, not the shown month that comes with clicking "next" or "prev".

编辑

我添加了 onChangeMonthYear 我在函数中使用datepicker的选项

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.

再次编辑

以上工作只需要设置延迟:]

the above worked just needed to set a delay :]

推荐答案

$ .datepicker('getDate')仅返回日期选择器的选定日期,而不是当前显示的月份。

$.datepicker('getDate') only returns the selected date of the datepicker, not the month that is currently being shown.

您正在寻找的是将函数绑定到 onChangeMonthYear 此处的文档

What you're looking for is to bind a function to onChangeMonthYear. Docs here

示例:

$('#calendar').datepicker('option', 'onChangeMonthYear', function(year, month) { var selectedMonth = month })

这篇关于jQuery datepicker得到的月份和年份不是最新的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆