更改 JQuery 日期选择器中禁用日期的颜色

发布于 2025-01-01 15:48:49 字数 955 浏览 2 评论 0原文

我正在使用 JQuery 来显示日历(日期选择器)。

我很容易地禁用了周末,然后我尝试禁用国庆日。

这是代码示例:

function checkHolidays(date, holidaysArray) {
    for (var i = 0; i < holidaysArray.length; ++i) {
        if (date.getMonth() == holidaysArray[i][0].getMonth()
            && date.getDate() == holidaysArray[i][0].getDate()) {
            return ([false, 'holiday', holidaysArray[i][1]]);
        }
    }
    return [true, ''];
}

这是有效的。但我想更改单元格的颜色(“假日”CSS 属性),但这不起作用。因为我将这一天设置为禁用,所以不会应用假日 css 属性。

但如果我不禁用日期,即:

return ([true, 'holiday', holidaysArray[i][2]]);

css 属性正在工作。有什么想法吗?

编辑:

我已将我的 css 规则更新为:

.holiday, .ui-datepicker .holiday span
{
     background: none #FFEBAF;
     border: 1px solid #BF5A0C;
}

现在它工作正常。

这篇文章帮助了我:如何更改单元格颜色

I'm using JQuery to display a calendar (datepicker).

I've disabled weekends easily and then I've tried to disable national days.

So here a sample of code:

function checkHolidays(date, holidaysArray) {
    for (var i = 0; i < holidaysArray.length; ++i) {
        if (date.getMonth() == holidaysArray[i][0].getMonth()
            && date.getDate() == holidaysArray[i][0].getDate()) {
            return ([false, 'holiday', holidaysArray[i][1]]);
        }
    }
    return [true, ''];
}

This is working. But I want to change the color of the cell (the 'holiday' css property) and this is not working. Because I'm setting the day as disabled, the holiday css property is not applied.

But if I do not disable the date, i.e:

return ([true, 'holiday', holidaysArray[i][2]]);

The css property is working. Got any idea?

Edit:

I've updated my css rule to:

.holiday, .ui-datepicker .holiday span
{
     background: none #FFEBAF;
     border: 1px solid #BF5A0C;
}

And now it's working perfectly.

This post helped me: How to change cell color

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文