我正在尝试使用beforeShowDay
禁用并突出显示日历中的日期。我发现此Fiddle代码有效。当我返回false
时,它可以工作并禁用那一天,但是我正尝试使用CSS类返回[false, 'holiday', '']
,但是它不起作用或没有禁用日期。
function add_zero(num){
if(num<10){
return '0'+num;
}else{
return num;
}
}
$('.date').datepicker({
format: "mm-dd-yyyy",
autoclose: true,
daysOfWeekDisabled: [0],
weekStart: [1],
beforeShowDay: function(Date) {
var array = <?php echo json_encode($arry); ?>;
var curr_day = add_zero(Date.getDate());
var curr_month = add_zero(Date.getMonth() + 1);
var curr_year = Date.getFullYear();
var curr_date = curr_month + '-' + curr_day + '-' + curr_year;
for (i = 0; i < array.length; i++) {
if (curr_date == array[i]) {
// return false;
return [false, 'holiday', ''];
}
}
//return [true,''];
return true;
}
}).on('changeDate', cal_date);
答案 0 :(得分:0)
大多数问题似乎都在您的php日期格式中。
var highlight = ['2019/05/19', '2019/05/20'];
//tips are optional but good to have
var tips = ['some description', 'some other description'];
var disable_dates = ['2019/05/01', '2019/05/08', '2019/05/15', '2019/05/22', '2019/05/29']
$('.date').datepicker({
format: "mm-dd-yyyy",
autoclose: true,
daysOfWeekDisabled: [0],
weekStart: [1],
beforeShowDay: function (date) {
var datestring = jQuery.datepicker.formatDate('yy/mm/dd', date);
var hindex = $.inArray(datestring, highlight);
if (hindex > -1) {
return [true, 'highlight yourcustomcss', tips[hindex]];
}
var aindex = $.inArray(datestring, disable_dates);
if(aindex == -1)
return [true,'custom_enabled']
else
return [false,'custom_disabled']
}
})