<script type="text/javascript">
$(document).ready(function(){
$("#start_week").datepicker({
beforeShowDay: nonWorkingDates,
numberOfMonths: 1,
firstDay: 1
});
function nonWorkingDates(date){
var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
var closedDays = [[Saturday], [Tuesday],[Wednesday],[Thursday],[Friday]];
for (var i = 0; i < closedDays.length; i++) {
if (day == closedDays[i][0]) {
return [false,'CLOSED'];
}
}
return [true,''];
}
});
</script>
“CLOSED”貌似是Datepicker内置的一个什么值,设置为”CLOSED”则当天的日期是不可选的。
ui.Datepicker.js里关于beforeShowDay的一些注释:
beforeShowDay: null, // Function that takes a date and returns an array with
// [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
// [2] = cell title (optional), e.g. $.datepicker.noWeekends
A function that takes a date as a parameter and must return an array with:
[0]: true/false indicating whether or not this date is selectable
[1]: a CSS class name to add to the date's cell or "" for the default presentation
[2]: an optional popup tooltip for this date
第三个参数可以在该日期上显示title,提示节假日名称。(比如国庆)
return [false, 'customCss','国庆'];
参考:http://www.itstrike.cn/Question/51bf073c-ef71-43cb-a6ce-e09ec3bc24da.html