jQuery datepicker noWeekends允许单个周末的一天

时间:2013-12-02 15:03:54

标签: jquery datepicker

我正在使用jQuery datapicker插件,并使用noWeekends函数禁用周末。唯一的问题是,我需要启用一个周末的一天。有谁知道如何做到这一点?这是我正在使用的代码...

var disabledDays = [<?php echo rtrim($daysClosed, ","); ?>];

function nationalDays(date) {
    var m = date.getMonth(), 
        d = date.getDate(), 
        y = date.getFullYear();

    for (i = 0; i < disabledDays.length; i++) {
        if ($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
                return [false, disabledDays[i][2] + '_day'];
            }
        }
        return [true, ''];
}

function noWeekendsOrHolidays(date) {
    var noWeekend = jQuery.datepicker.noWeekends(date);
    return noWeekend[0] ? nationalDays(date) : noWeekend;
    jQuery('.cart-contents i').html(noWeekend);
}

jQuery(document).ready(function(){

    jQuery('#e_deliverydate').datepicker({
        dateFormat: 'dd/mm/yy',
        beforeShowDay: noWeekendsOrHolidays,
        minDate:<?php echo $delivMin; ?>,
        maxDate:'<?php echo $oneYearOn; ?>' 
    });

});

提前致谢:)

1 个答案:

答案 0 :(得分:1)

fiddle Demo

$("#datepicker").datepicker({
    beforeShowDay: function (date) {
        var day = date.getDay();
        return [(day != 6)]; //0-Sunday 6-Saturday
    }
});

<小时/> 在OP的评论

之后更新

停用所有28th Dec

fiddle Demo

var array = ["28-12"];
$("#datepicker").datepicker({
    beforeShowDay: function (date) {
        var string = jQuery.datepicker.formatDate('dd-mm', date);
        return [array.indexOf(string) == -1]
    }
});

<小时/> 禁用28th Dec 2013

fiddle Demo

var array = ["28-12-2013"]; // add dates you want to disable here
$("#datepicker").datepicker({
    beforeShowDay: function (date) {
        var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
        return [array.indexOf(string) == -1]
    }
});

<小时/> 启用28th Dec

Updated fiddle Demo

$("#datepicker").datepicker({
    beforeShowDay: function (date) {
        var string = jQuery.datepicker.formatDate('dd-mm-yy', date);
        if (string == "28-12-2013") {
            return  [true];
        } else {
            var day = date.getDay();
            return [(day != 6)];
        }
    }
});