我有一个日期字段,并且想要设置相同的minDate。我为beforeShowDay定义了一个自定义范围,使得某些日期可选。我想使用setDate函数设置第一个可选日期。我怎样才能实现同样的目标?
例如:当我在就绪功能上使用它时, jQuery('#startDate')。datepicker(“setDate”,new Date());因此,在加载时间页面时,它将填充StartDate:09/27/2010。现在不是使用新的Date(),而是要填充第一个可选择的日期。
以下是我的相同代码:
<label>Start Date:</label><input type="text" id="startDate"></input>
<label>End Date:</label><input type="text" id="endDate"></input>
<script>jQuery(function() {
jQuery('#startDate, #endDate').datepicker();
jQuery('#startDate, #endDate').datepicker('option', {
beforeShow: customRange
});
//This populates with Values as current date in this format10/10/2010(I DONT WANT
//THIS...I WANT THE FIRST MINIMUM DATE of start date field TO BE SELECTABLE in this
//case it should be 10/11/2010 ??????????????????)
jQuery('#startDate').datepicker("setDate",new Date());
});
function customRange(input) {
if (input.id == 'endDate') {
//Get date from FromDate field
var startDate = jQuery('#startDate').datepicker("getDate");
//add 1 day in the From Date, so it become minDate for ToDate Field
var startDate_For_ToDate_Field = new Date(startDate.getFullYear(),
startDate.getMonth(), startDate.getDate()+1);
//add 30 dyas in the From Date,so it becomes maxDate for ToDate Field
var endDate_For_FromDate_Field= new Date(startDate.getFullYear(), startDate.getMonth(),
startDate.getDate()+31);
return {
numberOfMonths: 2,
minDate: startDate_For_ToDate_Field,
maxDate: endDate_For_FromDate_Field,
beforeShowDay:$.datepicker.noWeekends
};
} else if (input.id == 'startDate') {
$('#endDate').datepicker("setDate",null);
return {
numberOfMonths: 2,
minDate:'+1',
maxDate: jQuery('#endDate').datepicker("getDate")+'7',
beforeShowDay:$.datepicker.noWeekends
};
}
}
</script><script type="text/javascript">
谢谢, Dhiren
答案 0 :(得分:0)
$( ".selector" ).datepicker({ minDate: new Date(2007, 1 - 1, 1) });
了解更多信息: http://jqueryui.com/demos/datepicker/#option-minDate