我有两个日期选择器显示startdate和enddate。有一个带选项的选择框:
|daily|
|weekly|
|monthly|
|yearly|
假设所选选项是每周,并且在startdate中选择的日期是2013-03-28 ie;星期四。然后我需要禁用日历中除日期以外的所有其他日期。同样,如果选择月份并且startdate是2013-03-28,那么我想在enddate中禁用除每月28日之外的所有日期。我怎样才能做到这一点。
脚本
$( "#startdate" ).datepicker({
showButtonPanel: true,
dateFormat: 'yy-mm-dd',
minDate: 0,
changeYear: true,
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#enddate" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#enddate" ).datepicker({
showButtonPanel: true,
dateFormat: 'yy-mm-dd',
minDate: 0,
changeYear: true,
changeMonth: true,
numberOfMonths: 1,
onClose: function( selectedDate ) {
$( "#startdate" ).datepicker( "option", "maxDate", selectedDate );
}
});
答案 0 :(得分:1)
您可以这样实现:
$(function() {
var period = 'weekly';
var filterDate = function(date) {
var today = new Date();
if (period == 'weekly') {
if (today.getUTCDay() != date.getUTCDay()) {
return [false, "", ""];
}
} else if (period == 'monthly') {
if (today.getDate() != date.getDate()) {
return [false, "", ""];
}
}
return [true,"",""];
};
$("#period").change(function() {
period = $(this).val();
});
...
$( "#enddate" ).datepicker({
...
beforeShowDay: filterDate
});
});