jquery datepicker禁用特定日期

时间:2016-06-21 15:36:08

标签: javascript jquery datepicker

我正在尝试创建一个读取某个变量并在该变量中禁用该日期的日期选择器。

目前遵循此文档 http://t1m0n.name/air-datepicker/docs/#example-custom-content

但我似乎不太了解OnRenderCell:function

如何禁用2016年7月16日的特定日期

 onRenderCell: function (date, cellType) {
    if (cellType == 'month') {
        var day = date.getDay(),
            isDisabled = disabledDays.indexOf(day) != -1;

        return {
            disabled: isDisabled
        }
    }
}

1 个答案:

答案 0 :(得分:0)

var disabled_months = ["2016-1-1", "2016-2-1", "2016-6-1"];
var disabled_days   = ["2016-6-1", "2016-6-3", "2016-6-20"];
var disabled_years  = ["2014-1-1", "2013-1-1", "2000-1-1"];

$('#datepicker').datepicker({
    language: 'en',
    onRenderCell: function (date, cellType) {
        pretty_date = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
        var disabled = false

        if (cellType == 'month')
            disabled = disabled_months.indexOf(pretty_date) != -1

        else if (cellType == 'day')
            disabled = disabled_days.indexOf(pretty_date) != -1

        else if (cellType == 'year')
            disabled = disabled_years.indexOf(pretty_date) != -1

        return {disabled: disabled}
    }
});