bootstrap datepicker中的beforeShowDay禁用下一个日期

beforeShowDay in bootstrap datepicker disables the next date

本文关键字:下一个 日期 beforeShowDay datepicker 中的 bootstrap      更新时间:2023-09-26

我在一个页面上有多个日期拾取器,一旦我选择了一个,我想从下一个日期拾取器禁用它。我使用了下面的代码:

jQuery('.date-picker', jForm).datepicker({
    startDate: new Date(),
    autoclose: true,
    todayHighlight: true,
    beforeShowDay:function(Date){
        var curr_date = Date.toJSON().substring(0,10);
        if (forbidden.indexOf(curr_date)>-1) return false;        
    }
});

Forbidden是所选日期的数组,上面的代码禁用了下一天,而不是选中的一天(例如,如果我选择了2015-06-04,它会禁用2015-06-05)。

这里我没有使用bootstrap日期拾取器

var unavailableDates = ["19-8-2015","14-8-2015"];
function unavailable(date) {
    dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" +date.getFullYear();
    if ($.inArray(dmy, unavailableDates) < 0) {
        return [true,"","Book Now"];
    } else {
        return [false,"","Booked Out"];
    }
}
$('#unvailable').datepicker({ beforeShowDay: unavailable });