$(document).ready(function()
 {
 //設定當天日期為最小選取日
 var d = new Date();
 var year = d.getFullYear();
 var month = d.getMonth() + 1;
 var day = d.getDate()+1;
 // 封鎖的日期 YYYY/MM/DD
 var ArrDisabledDates = ["2016-4-4", "2016-4-5", "2016-5-2", "2016-6-9", "2016-6-10", "2016-9-15", "2016-9-16", "2016-10-10"]; 
 //此為要套用的 input
 $( "#txtPickupDate" ).datepicker(
 {
     dateFormat: 'yy-mm-dd',
     showOn: 'both',
     beforeShowDay: function(date)
     {
     var day = date.getDay();
     var year2 = date.getFullYear();
     var month2 = date.getMonth() + 1;
     var day2 = date.getDate();

     if(day == 0 || day ==6)
     {
         return [false,'周休二日'];//如果是周休二日也封鎖
     }
     OnOff1 = true;
     for(var i = 0 ; i < ArrDisabledDates.length ; i++ )
     {
         //如果日期等於封鎖的日期則進行動作
         if((year2+"-"+month2+"-"+day2).toString() == ArrDisabledDates[i].toString() )  
         {
             OnOff1 = false;
             return [false,'節慶假日'];
         }
         else
         {
             OnOff1 = true;
         }
     }
     if(OnOff1)
     {
         return [true,''];
     }
 },
 buttonImage: "http://order.exbtr.com/OrderEntrust/assets/images/calendar.png",    //套用圖形按鈕
 minDate:new Date(year, month - 1, day)  //設定最小選取日
 });
});



每個禮拜的周末封鎖效果圖如下

date

當九月份時候設定9/15~9/16為封鎖日期效果如下

 

september

 

Leave a Comment