2010-05-27 35 views
3

如何禁用使用jquery日期選取節假日列表?禁用jQuery的日期選取假期表

+3

可能重複[jQuery UI的日期選擇器 - 禁用特定的天數](http://stackoverflow.com/questions/677976/jquery-ui-datepicker-disable-specific-days) – Brandon 2010-05-27 14:15:52

+0

我覺得可能重複的是http ://stackoverflow.com/questions/2695961/jquery-datepicker-disable-federal-holidays – Suvonkar 2010-06-01 11:33:30

回答

1
var disabledDates = ['08/30/2010', '05/30/2010', '02/14/2011']; 

function noWeekendsOrHolidays(date) { 
     var noWeekend = $.datepicker.noWeekends(date); 
     if (noWeekend[0]) { 
      return disableDays(date); 
     } else { 
      return noWeekend; 
     } 
} 

function disableDays(date) { 
    for (var i = 0; i < disabledDates.length; i++) { 
     if (new Date(disabledDates[i]).toString() == date.toString()) {    
      return [false]; 
     } 
    } 
    return [true]; 
} 

$(.selector).datepicker({minDate: new Date(),beforeShowDay: noWeekendsOrHolidays, changeYear: true ,changeMonth: true});