Nan*_*ndu 6 jquery jquery-ui datepicker jquery-ui-datepicker
我有一个像这样的Jquery UI datepicker.

我只能从datepicker中选择月份和年份.
码:-
$('#datepicker').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'M yy',
maxDate: '0',
onClose: function() {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
},
beforeShow: function(input, inst) {
$(inst.dpDiv).addClass('calendar-off');
}
});
Run Code Online (Sandbox Code Playgroud)
如果我设置 maxDate: '0'最大月份和年份,我可以选择当前月份和当前年份.
我想使用jquery设置最大月份和年份.对于包含日期,月份,年份的普通日期选择器,首先我删除此maxDate: '0'代码,然后使用以下代码设置最大日期
var maximumDate = '07-15-2013';
$("#datepicker" ).datepicker( "option", "maxDate", maximumDate);
Run Code Online (Sandbox Code Playgroud)
如何设置月份和年份选择器的最大日期?上面的代码在这种情况下不起作用.请给我你的建议.
试过以下代码.对我来说工作正常.
var date = new Date("2013-07-15");
var currentMonth = date.getMonth();
var currentDate = date.getDate();
var currentYear = date.getFullYear();
$("#datepicker" ).datepicker( "option", "maxDate", new Date(currentYear, currentMonth, currentDate));
Run Code Online (Sandbox Code Playgroud)
我创建的示例小提琴:FIDDLE