禁用天jQuery UI Datepicker

时间:2014-05-09 10:37:52

标签: jquery jquery-ui datepicker

我希望能够禁用每年发生的一些银行假期,例如圣诞节,但我也希望能够禁用仅发生一年的日子

这是我的代码

  var unavailableDates = ["25-12", "26-12", "1-1"];

    function unavailable(date) {
        dmy = date.getDate() + "-" + (date.getMonth() + 1);
        if ($.inArray(dmy, unavailableDates) == -1) {
            return [true, ""];
        } else {
            return [false, "", "Unavailable"];
        }
    }


    function noWeekendsOrHolidays(date) {
        var noWeekend = jQuery.datepicker.noWeekends(date);
        return noWeekend[0] ? unavailable(date) : noWeekend;
    }

任何人都知道怎么做?

2 个答案:

答案 0 :(得分:1)

这样打电话:

$(".selector").datepicker({ beforeShowDay: noWeekendsOrHolidays})   

答案 1 :(得分:0)

http://api.jqueryui.com/datepicker/#option-beforeShowDay jQuery UI Datepicker的api

beforeShowDay    Type: Function( Date date )

Default: null
A function that takes a date as a parameter and must return an array with:
[0]: true/false indicating whether or not this date is selectable
[1]: a CSS class name to add to the date's cell or "" for the default presentation
[2]: an optional popup tooltip for this date
The function is called for each day in the datepicker before it is displayed. 

JQuery DatePicker and beforeShowDay

这可能会有所帮助

相关问题