2010-04-14 78 views
18

我有以下兩個日期選擇對象,但我不能得到我想要的,因爲我陷入與的minDate和的maxDate選項:jQuery的日期選擇器MINDATE,MAXDATE

這是限制日期未來日期。

我想要什麼:限制日期從當前日期到30年時間。

我得到的結果:限制從當前日期到10年的日期。

$(".datepickerFuture").datepicker({ 
    showOn: "button", 
    buttonImage: 'calendar.gif', 
    buttonText: 'Click to select a date', 
    duration:"fast", 
    changeMonth: true, 
    changeYear: true, 
    dateFormat: 'dd/mm/yy', 
    constrainInput: true, 
    minDate: 0, 
    maxDate: '+30Y',  
     buttonImageOnly: true 
    }); 

這是限制只選擇過去的日期

我想什麼:從當前的日期限制日期以120年前的時間。

我得到:限制從當前日期到120年前的時間日期,但是當我選擇了一年的最大年將恢復到選定的年份(例如什麼,我會得到從時新的一頁負荷1890- 2010年,但如果我選擇2000年的選擇框重置爲1880-2000)。

$(".datepickerPast").datepicker({ 
    showOn: "button", 
    buttonImage: 'calendar.gif', 
    buttonText: 'Click to select a date', 
    duration:"fast", 
    changeMonth: true, 
    changeYear: true, 
    dateFormat: 'dd/mm/yy', 
    constrainInput: true, 
    yearRange: '-120:0', 
    maxDate: 0, 
    buttonImageOnly: true 
}); 

我需要兩個datepicker對象的幫助,任何幫助將非常感激。

回答

6

我固定我的問題,它是jQuery的圖書館是有點出入日期。

如果有人對此解決方案感興趣,請檢查here

1

+30歲的應罰款如圖here

爲-120年,你只需要做逆here

+0

爲+30,那是什麼我想,但我只是+10年。 對於-120年,你是什麼意思? 謝謝。 – Amra 2010-04-14 16:06:43

+0

我剛剛使用'-120Y'爲minDate,0爲maxDate,如果您查看jsBin鏈接,您可以看到我使用的代碼 – 2010-04-14 16:21:42

+1

@Cesar - 年的下拉列表將根據當前年份進行更改。它似乎只顯示當前年份的-10/+ 10,但尊重您提供的最小/最大值。查看jQuery UI js文件中_generateMonthYearHeader的代碼。 – tvanfosson 2010-04-14 16:24:45

22
$("#datepick").datepicker({ 
      changeMonth: true, 
      changeYear: true, 
      showOn: 'button', 
      buttonImage: 'images/calendar.gif', 
      buttonImageOnly: true, 
      dateFormat: 'dd/mm/yy', 
      minDate: '-100Y', 
    maxDate: '-1Y', 
    yearRange: '-100', 

     }); 
+0

年份與最小/最大日期的年份+1。我不知道我可以設定這樣的日子。非常感謝! – 2014-02-07 15:28:55

1

從當前日期顯示1年=的maxDate: '+ 1Y', 從當前日期顯示爲30天=的maxDate: '+ 30D',

相關問題