Cha*_*rsh 3 arrays jquery jquery-ui date jquery-ui-datepicker
目前我有一个日期选择器:
如果在中午12:00之后排除今天.
不包括星期日.
<script type="text/javascript">
$(function() {
// get today's date
var myDate = new Date();
// add one day if after 12:00
if (myDate.getHours() > 12) {
myDate.setDate(myDate.getDate()+1);
} else {
myDate.setDate(myDate.getDate()+0);
};
$("#delivery-date-textbox").datepicker({
dateFormat: 'dd-mm-yy',
minDate: myDate,
beforeShowDay: function(date){ return [date.getDay() != 0,""]}
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它排除一系列公众假期?
它可能对你有帮助.... 点击这里
/* create an array of days which need to be disabled */
var disabledDays = ["2-21-2010","2-24-2010","2-27-2010","2-28-2010","3-3-2010","3-17-2010","4-2-2010","4-3-2010","4-4-2010","4-5-2010"];
/* utility functions */
function nationalDays(date) {
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
//console.log('Checking (raw): ' + m + '-' + d + '-' + y);
for (i = 0; i < disabledDays.length; i++) {
if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1 || new Date() > date) {
//console.log('bad: ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
return [false];
}
}
//console.log('good: ' + (m+1) + '-' + d + '-' + y);
return [true];
}
function noWeekendsOrHolidays(date) {
var noWeekend = jQuery.datepicker.noWeekends(date);
return noWeekend[0] ? nationalDays(date) : noWeekend;
}
/* create datepicker */
jQuery(document).ready(function() {
jQuery('#date').datepicker({
minDate: new Date(2010, 0, 1),
maxDate: new Date(2010, 5, 31),
dateFormat: 'DD, MM, d, yy',
constrainInput: true,
beforeShowDay: noWeekendsOrHolidays
});
});
Run Code Online (Sandbox Code Playgroud)
(David Walsh博客)