2014-10-18 25 views
3

我正在使用月份選擇器,我想限制用戶選擇未來的月份和年份。我怎樣才能做到這一點? 我嘗試使用如何在monthpicker中禁用未來的月份和年份

$("#month").monthpicker({ dateFormat: 'M-yy', 
      autoSize: true, 
      changeYear: true, 
      changeMonth: true, 
      showButtonPanel: true, 
      maxDate: new Date().getMonth() 

}); 

,但有了這個,我只能限制未來的一年裏,我仍然可以選擇未來的一個月。任何幫助將不勝感激。

+0

'的maxDate:新的Date()'就足夠了。無需放置'.getMonth()' – 2014-10-18 06:54:37

+0

這也只是限制未來的一年而不是一個月。我嘗試過這個。 – Fas 2014-10-18 06:56:40

+0

從來沒有聽說過monthpicker嘗試http://jsfiddle.net/Ls4bpcy4/ – user733421 2014-10-18 07:04:21

回答

0

默認情況下,年份範圍從10年前開始,到今年10年後結束,選擇當年。

這和其他設置可以在插件的初始化被覆蓋:

options = { 
pattern: 'yyyy-mm', // Default is 'mm/yyyy' and separator char is not mandatory 
selectedYear: 2010, 
startYear: 2008, 
finalYear: 2012, 
monthNames: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'] 

};

$('#custom_widget').monthpicker(options); 

你可以試試這個。這對我有用。

$('#my_widget').monthpicker('disableMonths', [1, 2, 11, 12]); 
$('#my_widget').monthpicker('disableMonths', []); // re-enables all months 

參考來源:Month Picker Jquery

+0

對不起,但這不是我正在尋找Ankur ... – Fas 2014-10-18 08:47:33

+0

您可以嘗試以上解決方案。 – 2014-10-18 10:12:07