jquery ui Datepicker 中为星期添加颜色

这段代码展示了如何使用JavaScript的jQuery UI Datepicker插件,结合一个预定义的节假日列表,来在日期选择器中突出显示节假日、周末。通过比较日期并应用不同的CSS类,实现了不同日期的背景和文字颜色变化,使得用户界面更加直观。
//休息日列表
var holidays = ['2021-12-05', '2021-12-13', '2021-02-11', '2021-03-21', '2021-04-29', '2021-05-03', '2021-05-04', '2021-05-05', '2021-07-21', '2021-09-15', '2021-09-23', '2021-10-13', '2021-11-03', '2021-11-23', '2014-12-23', '2014-12-24'];
 
$('#Date').datepicker({                       // 星期六和星期日变更颜色
beforeShowDay: function(date) {
for (var i = 0; i < holidays.length; i++) {
var holiday = new Date();
holiday.setTime(Date.parse(holidays[i]));   // 将节假日转换为日期类型
 
if (holiday.getYear() == date.getYear() &&  // 法定假日判断
holiday.getMonth() == date.getMonth() &&
holiday.getDate() == date.getDate()) {
return [true, 'class-holiday', '节假日'];
}
}
 
if (date.getDay() == 0) {                     // 星期天
return [true, 'class-sunday', '星期天'];
} else if (date.getDay() == 6) {              // 星期六
return [true, 'class-saturday', '星期六'];
} else {                                      // 工作日
return [true, 'class-weekday', '工作日'];
}
}
});


/* 背景 文字上色 */
.class-holiday > .ui-state-default {
background: #FFFFCC !important;
color: red !important;
}
.class-sunday > .ui-state-default {
background: #FFCCCC !important;
color: red !important;
}
.class-saturday > .ui-state-default {
background: #CCCCFF !important;
color: blue !important;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值