2013-09-05 57 views
0

我想用一個MySQL數據庫使用jquery datepicker來顯示任何有事件的日期。jquery datepicker css造型禁用日期

我已經設置showOtherMonths:true因爲偏好。

我想要做的是設置當前月份中的禁用日期,以便它們與其他月份中的日期不同。

如何爲此添加樣式?

$(document).ready(function() 
{ 
    var selected_dates = new Array(); 
    // get all the events from the database using AJAX 
    selected_dates = getSelectedDates(); 

    $('#datepicker').datepicker({ 
     dateFormat: 'yy-m-d', 
     inline: true, 
     showOtherMonths: true, 
     dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], 
     beforeShowDay: function (date) 
     { 
      // get the current month, day and year 
      // attention: the months count start from 0 that's why you'll need +1 to get the month right 
      var mm = date.getMonth() + 1, 
       dd = date.getDate(),  
       yy = date.getFullYear(); 
      var dt = yy + "-" + mm + "-" + dd; 

      if(typeof selected_dates[dt] != 'undefined') 
      { 
       // put a special class to the dates you have events for so you can distinguish it from other ones 
       // the "true" parameter is used so we know what are the dates that are clickable 
       return [true, " my_class"]; 
      } 

      return [false, ""]; 
     }   
    }); 
}); 

回答

1

您可以使用CSS高清

.ui-datepicker-other-month.ui-state-disabled:not(.my_class) span{ 
    color: red;  
} 

演示:Fiddle

+0

你從哪裏得到這些信息? – gibberish

+0

謝謝阿倫。我只是拿出:不(.my_class),改變背景顏色,而我得到了我想要的結果。正如胡言亂語所問,你從哪裏得到這些信息,因爲我需要做更多的造型? – AdRock