简体   繁体   English

使用下一个箭头时,jquery ui的日期选择器中返回的月份错误值

[英]wrong value returned for month in datepicker of jquery ui when using the next arrow

I am using datpicker to provide options to select the month/year only and when the month is selected, a form is submitted with the selected value. 我正在使用datpicker提供仅选择月份/年份的选项,并且当选择月份时,将提交具有所选值的表单。

here is the code: jquery ui datepicker with this code: 这是代码: jquery ui datepicker具有以下代码:

    $(document).ready(function(){
        $("#datepicker").datepicker( {
            changeMonth: true,
            changeYear: true,
            showButtonPanel: false,
            yearRange: "2013:2015",
            onChangeMonthYear: function(dateText, inst) { 
                console.log($(".ui-datepicker-year :selected",$(this)).val() 
                    + "/" + $(".ui-datepicker-month :selected",$(this)).val());
            }
        });
    });

but there are two situations when the number returned is wrong. 但是在两种情况下,返回的数字是错误的。

(values in console.log) (console.log中的值)

  1. if you try to select a month lets say oct 2013, returned value is 2013/9, which is ok. 如果您尝试选择一个月份,例如说2013年10月,则返回值为2013/9,可以。 now if you try to click on the arrow to go to nov 2013, again the value is 2013/9 which is wrong. 现在,如果您尝试单击箭头以转到nov 2013,则该值再次为2013/9,这是错误的。 similarly jumping from dec 2013 to jan 2012 returns 2013/11 同样从2013年12月跳至2012年1月,返回2013/11

  2. if you go to the end "dec 2015", and then click the next arrow, it goes back to the beginning "jan 2013", which is ok, but then keep clicking on the next arrow, you will notice you can no longer move from "dec 2013" to "jan 2014", it moves back to "jan 2013" 如果您移至末尾的“ dec 2015”,然后单击下一个箭头,它将返回到开头的“ jan 2013”​​,这没关系,但是继续单击下一个箭头,您会注意到您将无法再移动从“ 2013年12月”到“ 2014年1月”,然后又回到“ 2013年1月”

any help is appreciated. 任何帮助表示赞赏。

onChangeMonthYear() receives the newly selected year and month as arguments, so you can just use those directly onChangeMonthYear()接收新选择的年份和月份作为参数,因此您可以直接使用它们

            ...
            minDate: new Date(2013, 1 - 1, 1),
            maxDate: new Date(2015, 12 - 1, 31),
            onChangeMonthYear: function(year, month, inst) { 
                console.log(
                    year + "/" + month
                );
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用jquery ui datepicker重新聚焦相同的datepicker输入时显示错误的月份和年份 - Show wrong month and year when refocused same datepicker input with using jquery ui datepicker jQuery UI Datepicker-隐藏特定月份的上一个导航箭头 - jQuery UI Datepicker - Hide previous navigation arrow for a specific month JQuery UI datepicker如何显示月导航的下一个上一个箭头? - JQuery UI datepicker how to show next prev arrows for month navigation? 单击上一个/下一个月时,阻止jQuery Datepicker刷新 - Stop jQuery Datepicker from refreshing when clicking previous/next month 点击下个月后jQuery Datepicker打开两次(使用2个Datepickers) - jQuery Datepicker opens twice after click on next month (using 2 Datepickers) 在jQuery UI datepicker中使用minDate / maxDate时如何使prev / next按钮可见? - How to make prev/next buttons visible when using minDate/maxDate in jQuery UI datepicker? 单击jquery UI datepicker的上一个/下一个时,模态隐藏 - Modal is hiding when the Prev/Next of jquery UI datepicker is clicked jquery datepicker beforeShowDay工作错误的一个月? - jquery datepicker beforeShowDay works for wrong month? 在jQuery UI Datepicker上仅显示月份 - Showing only month on jquery ui datepicker 年份和月份选择的jQuery UI DatePicker不起作用 - jQuery UI DatePicker for month and year selection is not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM