Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript datepicker在ShowDay返回前3个月_Javascript_Jquery_Datepicker - Fatal编程技术网

Javascript datepicker在ShowDay返回前3个月

Javascript datepicker在ShowDay返回前3个月,javascript,jquery,datepicker,Javascript,Jquery,Datepicker,我需要在jquery datepicker日历中禁用某一天,因此在beforeShowDay函数中,我编写了以下内容: beforeShowDay: function(date){ if(parseInt(calMonth) != parseInt(date.getMonth())){ calMonth = date.getMonth(); alert(calMonth + ' - ' + date.getM

我需要在jquery datepicker日历中禁用某一天,因此在beforeShowDay函数中,我编写了以下内容:

beforeShowDay: function(date){
            if(parseInt(calMonth) != parseInt(date.getMonth())){
                calMonth = date.getMonth();
                alert(calMonth + ' - ' + date.getMonth());
            }
            return {0: true};
        }
其中calMonth包含当前月份编号。现在,如果我运行此命令,我会收到3个警报,按顺序显示: 9-9、10-10和11-11。为什么我有3条消息,但它不应该显示任何内容(因为当我打开datepicker时,它默认显示当前月份的日历,所以if(parseInt(calMonth)!=parseInt(date.getMonth())应该返回false)。
我还设置了numberOfMonths:1。

也有同样的问题,我就是这样解决的:

$("#datepicker").datepicker({ showWeek: true, showOtherMonths : false,
    //I'm using onChangeMonthYear to always keep my datepicker month updated
    onChangeMonthYear: function(year, month, inst){
        $(this).datepicker( "setDate", month + '/1/' + year );
    },
    beforeShowDay: function(date) {
        //Now I can get only the days of the current selected month, and do whatever I want...
        if(date.getMonth()==$(this).datepicker('getDate').getMonth()) 
            console.log(date.getDate()+' - '+date.getMonth()+' - '+$(this).datepicker('getDate').getMonth());

        //keep returning as usual to the datepicker
        return [true, ''];
    } 
});

希望有帮助=)

也有同样的问题,我就是这样解决的:

$("#datepicker").datepicker({ showWeek: true, showOtherMonths : false,
    //I'm using onChangeMonthYear to always keep my datepicker month updated
    onChangeMonthYear: function(year, month, inst){
        $(this).datepicker( "setDate", month + '/1/' + year );
    },
    beforeShowDay: function(date) {
        //Now I can get only the days of the current selected month, and do whatever I want...
        if(date.getMonth()==$(this).datepicker('getDate').getMonth()) 
            console.log(date.getDate()+' - '+date.getMonth()+' - '+$(this).datepicker('getDate').getMonth());

        //keep returning as usual to the datepicker
        return [true, ''];
    } 
});

希望有帮助=)

您是否启用了
showOtherMonths
选项?这将显示几个月后的几天。此外,您的函数更改了calMonth,因此它并不总是当前月份。我将showOtherMonths设置为false,但仍收到3条警报。是的,我更改了calMonth,因为当月份更改时,我只需要执行一次ajax调用,所以如果我不将calMonth设置为日历显示的当前月份,它将执行31次ajax调用。现在我看到有一个名为onChangeMonthYear的选项,可能在这种情况下使用这个选项是正确的。无论如何,谢谢你;)是否启用了“显示其他月份”选项?这将显示几个月后的几天。此外,您的函数更改了calMonth,因此它并不总是当前月份。我将showOtherMonths设置为false,但仍收到3条警报。是的,我更改了calMonth,因为当月份更改时,我只需要执行一次ajax调用,所以如果我不将calMonth设置为日历显示的当前月份,它将执行31次ajax调用。现在我看到有一个名为onChangeMonthYear的选项,可能在这种情况下使用这个选项是正确的。无论如何,谢谢你;)