我想将jQuery UI的maxDate
设置为18/02/2013
,但在尝试时,它只允许我将其更新到今天的日期。
我该怎么做呢?
$("#datepicker'.$row['id'].'").datepicker({
minDate: -0,
dateFormat: \'dd/mm/yy\',
maxDate: 18/02/2013
});
答案 0 :(得分:29)
试试这个:
$("#datepicker").datepicker({ minDate: -0, maxDate: new Date(2013, 1, 18) });
如果您想使用硬编码日期,请使用new Date(2013, 1, 18)
模式。
如果您想使用通用模式,请使用"+1D +1M +1Y"
。
答案 1 :(得分:1)
$(document).ready(function() {
$( "#dob" ).datepicker({
maxDate: -0,
changeMonth:true,
changeYear:true,
yearRange:"-100:+100",
dateFormat: "yy-mm-dd",
});
});
答案 2 :(得分:0)
$( "#datepicker" ).datepicker( { minDate: 0, maxDate: 365 });
//365 Days
您还可以使用天数。
答案 3 :(得分:0)
这对我来说很有效,方法是将结束日期选择器的范围从今天设置为另外7天。
$endDateCtrl.datepicker("option", "minDate", -0);
$endDateCtrl.datepicker("option", "maxDate", '+7D');
$endDateCtrl.datepicker();
答案 4 :(得分:0)
我正在使用事件函数设置最大日期:
$('#datepicker').datepicker({
changeMonth: true,
changeYear: true,
yearRange: "-9:+1",// you can define range of year here.
dateFormat: 'MM yy',
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 () {
var selDate = $(this).val();
if ((selDate.length) > 0) {
iYear = selDate.substring(selDate.length - 4, selDate.length);
iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5),
$(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(lastYear, iMonth, 1));
$(this).datepicker('option', 'maxDate', new Date(lastYear, 12, 1));
$(this).datepicker('setDate', new Date(lastYear, iMonth, 1));
}
}
});