1

我如何动态禁用特定日期,为此我正在使用此代码:-

<div id="disableVal_12">1,2</div>

<script>
    var daysToDisable = [$("#disableVal_12").html()];
    $('#datepickerPospond_2').datepicker({
        firstDay:1,
        beforeShowDay: disableSpecificWeekDays
    });
    function setDateZero(date){
        return date < 10 ? '0' + date : date;
    }
    function disableSpecificWeekDays(date) {

        var day = date.getDay();
        var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
        var date = setDateZero(d) + '/' + setDateZero((m+1)) + '/' + y;
        for (i = 0; i < daysToDisable.length; i++) {
            if ($.inArray(day, daysToDisable) == -1) {
                return [false];
            }else if ($.inArray(date , datesToDisable) == 1) {
                return [false];
            }
        }
        return [true];
    }
</script>

如果有人有更好的解决方案,请告诉我。

4

1 回答 1

2

示例代码:

var unavailableDates = ["9-5-2011","14-5-2011","15-5-2011"];

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

$('#iDate').datepicker({ beforeShowDay: unavailable }); 

看这里这里

于 2013-05-23T05:37:34.307 回答