在这里,我想实现以下目标
>突出显示日期选择器中的所有假期
>在日期选择器中禁用特定日期
>在日期选择器中禁用特定周末
我有各自的片段,但我想要一起
小提琴:Working Demo
突出显示假期
var holydays = ['10/17/2013','10/18/2013','11/2/2013']; function highlightDays(date) { for (var i = 0; i < holydays.length; i++) { if (new Date(holydays[i]).toString() == date.toString()) { return [true,'highlight']; } } return [true,'']; } $(function () { $("#dp").datepicker({ minDate: 0,dateFormat: 'mm/dd/yy',inline: true,numberOfMonths: [1,2],dayNamesMin: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],beforeShowDay: highlightDays,}); });
禁用特定日期
var disabledDays = ["10-20-2013","10-21-2013","11-15-2013","11-17-2013"]; function disableAllTheseDays(date) { var m = date.getMonth(),d = date.getDate(),y = date.getFullYear(); for (i = 0; i < disabledDays.length; i++) { if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) { return [false]; } } return [true]; }
禁用周末
$(function() { $( "#availability" ).datepicker({ minDate: 0,beforeShowDay: $.datepicker.noWeekends }); });
任何人都可以帮助我..
提前致谢.
解决方法
改变:
$(function () { $("#dp").datepicker({ minDate: 0,beforeShowDay: setCustomDate // <-----change function }); });
function setCustomDate(date) { var clazz = ""; var arr1 = highlightDays(date); if (arr1[1] != "") clazz = arr1[1]; var arr2 = disableAllTheseDays(date); var arr3 = $.datepicker.noWeekends(date); return [(!arr2[0] || !arr3[0]) ? false : true,clazz]; }