我正在开发ASP.net Webform应用程序,我需要阻止某些日期和周末作为周五和周日星期六。
以下代码工作正常,它会阻止日期,但默认情况下阻止星期六和星期六星期天作为周末,我需要阻止所有星期五&星期六在日历上。
我很感激修复此特定代码。我不确定jQuery Calendar是否有内置属性来指定不同的周末
var holiDays = [[2012, 07, 06, 'New Years Day'], [2012, 07, 14, 'Event XYZ'], [2011, 17, 25, 'Christmas Day']];
$(function () {
$("#<%=txtBookDate.ClientID %>").datepicker({
dateFormat: "yy-mm-dd",
minDate: "-0d",
maxDate: "+60d",
beforeShowDay: noWeekendsOrHolidaysOrBlockedDates
});
function noWeekendsOrHolidaysOrBlockedDates(date) {
var noWeekend = jQuery.datepicker.noWeekends(date);
return noWeekend[0] ? setHoliDays(date) : noWeekend;
}
// set holidays function which is configured in beforeShowDay
function setHoliDays(date) {
for (i = 0; i < holiDays.length; i++) {
if (date.getFullYear() == holiDays[i][0]
&& date.getMonth() == holiDays[i][1] - 1
&& date.getDate() == holiDays[i][2]) {
return [false, 'holiday', holiDays[i][3]];
}
}
return [true, ''];
}
});
答案 0 :(得分:2)
您无权访问jQuery UI源吗?奇怪,因为它是javascript,通常免费提供:
/* Set as beforeShowDay function to prevent selection of weekends.
@param date Date - the date to customise
@return [boolean, string] - is this date selectable?, what is its CSS class? */
noWeekends: function(date) {
var day = date.getDay();
return [(day > 0 && day < 6), ''];
}
看起来非常不可定制,但相对容易重新实现为您自己的功能。