2011-09-08 175 views
1

我使用jQuery UIDatePicker爲我的網站上的消費者選擇出生日期。它目前通過下拉式顯示月份和年份。例如,當我通過maxDate將年限制爲-18y時,月份下拉式不顯示選擇1993年的所有月份。它只顯示直到最大月份的月份。在選擇器中顯示日期範圍外的日期範圍?

在可用性測試中,我們發現,我們的人口趨於點擊他們的誕生,那麼一年,然後一天的一個月。

是否有辦法顯示所有月份,即使該月份內的日期不可選?

這裏是用來顯示的DatePicker代碼:

$('.DobWidget').datepicker({ 
    showOn: 'both',   
    buttonImage: '/media/img/admin/icon_calendar.gif', 
    buttonImageOnly: true, 
    dateFormat: js_date_format, // mm/dd/yyyy 
    constrainInput: false, // Handled server-side for type-in. 
    changeMonth: true, 
    changeYear: true, 
    maxDate: '-18y', 
    minDate: '-110y', 
    showButtonPanel: true, 
    onChangeMonthYear: function(year, month, inst) { 
     if (inst.currentDay != 0) {  
      $(this).datepicker("setDate", new Date(year, month - 1, inst.currentDay)); 
     }     
    } 
}); 
我目前使用的jQueryUI的v.1.8.16和jQuery v.1.6.3

,兩者均由谷歌AJAX API的提供。

+0

我看到1990年沒有問題,難道是1993年? –

+0

你是對的。我有兩個範圍,21和18.我把它們混淆爲例子。 1993年是正確的一年。 –

回答

0

修正了jQuery UI的1.8.17 我也有這個問題,我在由jQuery代碼改變一些事情的工作。現在我看到所有的月份,我可以選擇它們,但日期仍然是不可選的,只要你想。

在_generateHTML功能if語句添加maxDraw.setMonth('11' ):在

if (maxDate) { 
      maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw); 
      maxDraw.setMonth('11'); 
      while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) { 
       ... 
      } 
     } 

在_generateMonthYearHeader功能else語句的循環中,您更改:

for (var month = 0; month < 12; month++) { 
       if ((!inMinYear || month >= minDate.getMonth()) && 
         (!inMaxYear || month <= maxDate.getMonth())) 
        monthHtml += '<option value="' + month + '"' + 
         (month == drawMonth ? ' selected="selected"' : '') + 
         '>' + monthNamesShort[month] + '</option>'; 
      } 

變成

for (var month = 0; month < 12; month++) { 
       if ((!inMinYear || month >= minDate.getMonth()) && 
         (!inMaxYear || month <= 11)) 
        monthHtml += '<option value="' + month + '"' + 
         (month == drawMonth ? ' selected="selected"' : '') + 
         '>' + monthNamesShort[month] + '</option>'; 
      } 

在_restrictMinMax中添加maxDate.setMonth('11'):

... 
var maxDate = this._getMinMaxDate(inst, 'max'); 
     maxDate.setMonth('11'); 
     var newDate = (minDate && date < minDate ? minDate : date); 
... 

在_isInRange添加maxDate.setMonth('11' ):

var minDate = this._getMinMaxDate(inst, 'min'); 
     var maxDate = this._getMinMaxDate(inst, 'max'); 
     maxDate.setMonth('11'); 
...