【问题标题】:Datepicker add css dayDatepicker 添加 css 日期
【发布时间】:2015-09-30 15:00:08
【问题描述】:

我使用 jquery ui datepicker,我想根据时间数组为一天着色一个框。问题是我想在不同的日子添加颜色,而不必创建所有 css 类,只需添加十六进制颜色。这是我的代码:

  $('.datepicker').datepicker({
        changeMonth: true,
        changeYear: true,
        beforeShowDay: function (date) {
            var month = date.getMonth()+1;
            var day =  date.getDate();

            if (month < 10) {
                month = '0' + month;
            }

            if (day < 10) {
                day = '0' + day;
            }

            return [true, $.inArray(the_day, tab_days) >= 0 ? "odd" : ''];
        }
    });

Css 类:

.odd a.ui-state-default {
    color:white;
    background-color: red;
    background: red;
}

这个版本有效,但每天都有相同的颜色,我会这样做:

      $(this).css("background-color", hexa color);

【问题讨论】:

    标签: javascript jquery css jquery-ui datepicker


    【解决方案1】:

    您可以做的一件事是将 RGB 转换为十六进制。像这样

    function rgbToHex(r, g, b) {
        return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
    }
    
    $(this).css("background-color", rgbToHex(rIn,gIn,bIn));
    

    只需将您的输入值更改为您想要的任何值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      相关资源
      最近更新 更多