2012-03-28 79 views
1

我想修改jQuery datepicker在其他月的其他月份在多月模式下不重複的日子(見下圖,我想刪除紅色標記的日子)。你可以幫我嗎?jQuery datepicker多月模式重複周

enter image description here

至於你問,這是我的日曆代碼:

$(document).ready(function(){ 
    var weeks = new Array(); 

    function inWeeks(startDate) { 
     for (var i in weeks) { 
      if (weeks[i].getTime() == startDate.getTime()) return true; 
     } 
     return false; 
    } 

    function removeWeek(startDate) { 
     for (var i in weeks) { 
      if (weeks[i].getTime() == startDate.getTime()) { 
       weeks.splice(i, 1); 
       return; 
      } 
     } 
    } 

    function addWeek(startDate) { 
     weeks.push(startDate); 
    } 

    var selectCurrentWeek = function() { 
     window.setTimeout(function() { 
      $('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active') 
     }, 1); 
    } 

    $('.week-picker').datepicker({ 
     numberOfMonths: 2, 
     showOtherMonths: true, 
     selectOtherMonths: true, 
     hideIfNoPrevNext: true, 
     firstDay: 1, 
     onSelect: function(dateText, inst) { 
      var date = $(this).datepicker('getDate'); 
      var startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1); 
      //var endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6); 

      if (inWeeks(startDate)) { 
       removeWeek(startDate); 
      } else { 
       addWeek(startDate); 
      } 

      selectCurrentWeek(); 
     }, 
     beforeShowDay: function(date) { 
      var cssClass = ''; 
      for (var i in weeks) { 
       var startDate = weeks[i]; 
       var endDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() - startDate.getDay() + 7); 
       if(date >= startDate && date <= endDate) 
        cssClass = 'ui-datepicker-selected-week-day'; 
      } 
      return [true, cssClass]; 
     }, 
     onChangeMonthYear: function(year, month, inst) { 
      selectCurrentWeek(); 
     } 
    }); 
}); 
+0

您使用的是什麼日期選擇器?你的代碼是什麼樣的? – 2012-03-28 12:55:27

+0

標準的jQuery datepicker(jquery-1.6.2,jquery-ui-1.8.14.custom) – 2012-03-28 12:58:44

+4

正如@AndrewWhitaker所說,我們需要您發佈一段代碼。你想做的事情在jQuery的演示頁面上工作得很好...... http://jqueryui.com/demos/datepicker/#multiple-calendars – Jibou 2012-03-28 13:05:21

回答

1

你應該擺脫那些兩條線:

showOtherMonths: true, 
selectOtherMonths: true, 

選項showOtherMonths「顯示日期在當月開始或結束時的其他月份(不可選擇)「和selectOtherMonths」如果顯示其他月份的真實天數當前月份之前或之後都可以選擇。「