2013-07-19 35 views
0

我正在開發一個利用jQuery datepicker的項目,並試圖使用showWeek屬性來顯示日曆旁的週數。更改jquery datepicker上的開始周ShowWeek

我的問題是我不想'1周'在1月1日開始,而是在8月1日開始。

有什麼辦法可以實現嗎?

謝謝

+0

您可以使用calculateWeek,然後做必要的數學調整爲8月1日? – jeff

+0

有可能,但是我需要將這些數據傳回到日期選擇器列周 - 這是我無法弄清楚的部分。 –

+0

查看文檔http://api.jqueryui.com/datepicker/#option-calculateWeek,因爲它可能會解釋您需要執行的操作。 – jeff

回答

0

與下個月工作不適合上一個月,所以我已禁用上一個月。

如果當前月份少於8月份,則日曆將始終與8月份一起打開,而不是從上一年8月份開始。

工作演示http://jsfiddle.net/cse_tushar/dR429/4

$(document).ready(function() { 
    i = 0; 
    month_set = 8; 
    var d = new Date(); 
    week = (Math.ceil(Math.round(((new Date(d.getFullYear() + 1, 1)) - (new Date(d.getFullYear(), 1)))/86400000)/7)); 
    current_year = ((d.getMonth() + 1) >= month_set) ? d.getFullYear() : d.getFullYear() - 1; 

    function myWeekCalc() { 
     i++; 
     return i = (i > week) ? 0 : i; 
    } 
    $("#d1").datepicker({ 
     showWeek: true, 
     defaultDate: new Date(current_year, month_set-1, 1), 
     calculateWeek: myWeekCalc, 
     onClose: function() { 
      i = 0; 
     }, 
     onChangeMonthYear: function (year, month) { 
      var diff = month - month_set; 
      var d = new Date(month + ' 1' + ',' + year); 
      if (d.getDay() != '0') { 
       i--; 
      } 
      if (month == month_set) { 
       i = 0; 
      } 
      if (current_year != year && month == month_set) { 
       week = (Math.ceil(Math.round(((new Date(year + 1, 1)) - (new Date(year, 1)))/86400000)/7)); 
      } 
     } 
    }).focus(function() { 
     $(".ui-datepicker-prev").remove(); 
    }); 
}); 
相關問題