问题
jQuery UI Datepicker:
Hi,
I'm trying to have the pop-up calendar allow only the Monday dates in the future to be selected. I've tried this code:
$(function() {
$('#dateWeekly').datepicker({
showOn: 'both', // use to enable calendar button and focus
buttonImage: 'childtime/images/calendar.gif',
buttonImageOnly: true,
buttonText: 'Show Calendar',
numberOfMonths: 3,
showButtonPanel: true,
minDate: -0, maxDate: '+12M',
// beforeShowDay: function(date){ return [date.getDay() == 1,""]}
beforeShowDay: function(date) { return [date.getDay() == 1, "" && date.getTime() != today.getTime(), ""]; }
});
});
This disables all past dates, and disables all future days except Mondays (so far so good), but it fails to disable today's date if today is Monday. Any suggestions will be appreciated. Thanks!
回答1:
Set minDate to +1d.
As you are supposed to pick only future mondays, today shouldn't be able to be picked, no matter what day it is.
And you can simplify your beforeShowDay to:
beforeShowDay: function(date) {
return [date.getDay() == 1, ""];
}
回答2:
Below Code might be the solution for this question.
beforeShowDay: function(date) {
returnFlag = true;
currentDate = new Date();
if( date.getDay() == 1 && date.getDate() == currentDate.getDate()
&& date.getMonth() == currentDate.getMonth()){
returnFlag = false;
}
return [returnFlag,'',false];
}
回答3:
Maybe that could help
$(function() {
$('#dateWeekly').datepicker({
showOn: 'both', // use to enable calendar button and focus
buttonImage: 'childtime/images/calendar.gif',
buttonImageOnly: true,
buttonText: 'Show Calendar',
numberOfMonths: 3,
showButtonPanel: true,
minDate: -0, maxDate: '+12M',
beforeShowDay: function(date) {
// from here
var selectable = true;
var today = new Date()
if( today.getDay() == 1 && date.getDate() == today.getDate() )selectable = false;
return [selectable,'',false];
// til here
}
});
});
来源:https://stackoverflow.com/questions/3247656/jquery-ui-datepicker-disable-todays-date-if-today-is-monday