簡體   English   中英

如何在jQuery Datepicker中禁用工作日和自定義日?

[英]How to disable weekdays and custom days in jquery datepicker?

這是我下面的代碼,我需要禁用工作日,並且在給定的日子里我該怎么做? 有人能幫我嗎 ?

jQuery 小提琴

$(document).ready(function(){
var Desingndate = $('#DesignIdUnavialble').html();
var splitdate = Desingndate.split(',');
   // console.log(splitdate.length);
    var arrDisabledDates = {};
    for (var i = 0; i < splitdate.length; i++) {
        //console.log(splitdate[i]);    
    arrDisabledDates[new Date(splitdate[i])] = new Date(splitdate[i]);    
    }

     $("#iDate").datepicker({       
        dateFormat: 'dd-mm-yy',
        beforeShowDay: function (dt) {
            var bDisable = arrDisabledDates[dt];
            if (bDisable) return [false, '', ''];
            else return [true, '', ''];
        }
    });

});

在這里查看

我修改了您的else語句以禁用所有工作日:

var bDisable = arrDisabledDates[dt];
if (bDisable) return [false, '', ''];
else {
    return [dt.getDay() == 6 || dt.getDay() == 0,""];
}

工作小提琴

這可能對您有幫助

function deadlinedates(date) {
      dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
      var day = date.getDay();

        var Desingndate = $('#DesignIdUnavialble').html();
        var splitdate = Desingndate.split(','); 
        var arrDisabledDates = {};
        for (var i = 0; i < splitdate.length; i++) {        
        arrDisabledDates[new Date(splitdate[i])] = new Date(splitdate[i]);    
        }

       var bDisable = arrDisabledDates[date];
       if (bDisable) return [false, '', ''];
       else return [(day != 0 && day != 6)];

    }


$(document).ready(function(){

     $("#iDate").datepicker({       
        dateFormat: 'dd-mm-yy',
        beforeShowDay: deadlinedates
    });

});

暫無
暫無

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

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