在jQuery datepicker中禁用特定月份的特定日期

时间:2018-10-10 07:45:49

标签: jquery jquery-ui datepicker jquery-ui-datepicker

使用jQuery Datepicker禁用特定月份(即5月1日至9月28日)的特定月份的特定日期(即,星期日-星期五仅启用星期六)。

对于其余日期(9月29日至4月30日),应允许选择所有工作日。

1 个答案:

答案 0 :(得分:0)

您可以使用:https://api.jqueryui.com/datepicker/#option-beforeShowDay

仅启用星期六的示例:

<input />

$('input').datepicker({
    beforeShowDay: function(date){
        var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        return [(date.getDay()==6)?1:0]
    }
});

编辑1:

$('input').datepicker({
    beforeShowDay: function(date){
                var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
        if((date.getMonth()<4) || (date.getMonth()>=8)){
            if(date.getMonth()==8 && date.getDate()<28){
            return[0];
          } else {
            return [1];
          } 
        } else {
            return [(date.getDay()==6)?1:0];
        }

    }
});
相关问题