【问题标题】:jquery datepicker css styling disabled datesjquery datepicker css 样式禁用日期
【发布时间】:2013-09-05 16:00:45
【问题描述】:

我正在尝试使用带有 MySQL 数据库的 Jquery datepicker 来显示任何有事件的日期。

出于偏好,我设置了 showOtherMonths: true

我想做的是设置当月禁用日期的样式,使它们与其他月份的日期颜色不同。

我怎样才能为此添加样式?

$(document).ready(function() 
{
    var selected_dates = new Array();
    // get all the events from the database using AJAX
    selected_dates = getSelectedDates();

    $('#datepicker').datepicker({
        dateFormat: 'yy-m-d',
        inline: true,
        showOtherMonths: true,
        dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        beforeShowDay: function (date)
        {
            // get the current month, day and year
            // attention: the months count start from 0 that's why you'll need +1 to get the month right
            var mm = date.getMonth() + 1, 
                dd = date.getDate(),    
                yy = date.getFullYear();
            var dt = yy + "-" + mm + "-" + dd;

            if(typeof selected_dates[dt] != 'undefined')
            {
                // put a special class to the dates you have events for so you can distinguish it from other ones
                // the "true" parameter is used so we know what are the dates that are clickable
                return [true, " my_class"];
            }

            return [false, ""];
        }           
    });
});

【问题讨论】:

    标签: jquery css jquery-ui-datepicker


    【解决方案1】:

    你可以使用css def

    .ui-datepicker-other-month.ui-state-disabled:not(.my_class) span{
        color: red;    
    }
    

    演示:Fiddle

    【讨论】:

    • 谢谢阿伦。我刚刚取出 :not (.my_class) 并更改了背景颜色,我得到了我想要的结果。正如胡言乱语问的那样,你从哪里得到这些信息,因为我需要做更多的造型?
    【解决方案2】:

    我将下面的代码添加到自定义 Style.css 中,它就像一个魅力。

    .ui-datepicker-unselectable .ui-state-default {
        background: yellow;
        color: red;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-28
      • 1970-01-01
      • 2020-10-27
      • 2017-07-31
      • 2021-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多