2013-05-14 64 views
1

使用jQuery Datepicker進入一個奇怪的問題。我已設置選項changeMonth:true以啓用月份更改。JQuery Datepicker日期僅在點擊該日期時被捕獲

說,如果我的日期選擇器顯示的日期2013年2月5日,當我剛剛一個月改爲四月(不點擊任何一天在控制),日期被顯示爲2013年2月4日。但是,當我從控制中得到日期時,我最終得到的是舊的月份值而不是新選擇的值。

代碼:

$('#uxStartDateTime').datetimepicker({ 
    timeFormat: "hh:mm tt", 
    dateFormat: "dd/mm/yy", 
    showButtonPanel: false, 
    changeMonth: true, 
    changeYear: true 
}); 

//getting the date 
var startDate = $('#uxStartDateTime').datetimepicker('getDate'); 

//formatting this date to it send via ajax to c# 
startDate = startDate.getFullYear() + "-" + (startDate.getMonth() + 1) + "-" + startDate.getDate() + " " + startDate.getHours() + ":" + startDate.getMinutes(); 

有什麼毛病我的方法還是這是一個已知的問題?

+2

它應該是這樣的,你可以在幾個月之間來回滾動,但你必須實際選擇一個日期來改變日期,這是幾乎每個日期選擇器的工作方式! – adeneo 2013-05-14 16:29:10

+0

@adeneo哦,我明白了。有沒有什麼方法可以克服這種行爲? – Devin 2013-05-14 16:35:34

回答

2

正如adeneo在他的評論中指出的那樣,這是預期的日期選擇器行爲。如果你想改變這一點,你將不得不編寫一個月份更改時觸發的方法。

$('.ui-datepicker-month').change(function() { 
    // if there is a value in your controller, change it 
}); 

我會離開加/減月份的實際邏輯給你一個日期。

+0

謝謝,我感到困惑,因爲當我改變月份時,文本字段顯示更新值。 – Devin 2013-05-14 16:44:29