簡體   English   中英

datepicker beforeShowDay返回3個月

[英]datepicker beforeShowDay return 3 months

我需要在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, ''];
    } 
});

希望對您有幫助=)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM