0
我有一個日期字段,並希望爲相同的設置minDate。有一個自定義範圍,我已經爲beforeShowDay定義了一些日期選擇。我想要使用setDate函數設置第一個可選日期。我怎樣才能達到相同的目的? ('#startDate')。datepicker(「setDate」,new Date());所以在頁面加載的時候,它被填充StartDate:09 /二千〇一十分之二十七。現在,而不是使用新的日期(),我想第一次可選日期被填充。jQuery - 獲取minDate值並設置該值
這裏是我的同一代碼:
<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
Sathis嗨,感謝您的輸入,但我已經瀏覽了jQuery的日期網站。爲了更清晰地編輯我的問題。希望能夠得到某個人的迴應。 – 2010-10-10 11:42:06