【问题标题】:DatePicker as a readonly calendarDatePicker 作为只读日历
【发布时间】:2015-01-14 15:11:14
【问题描述】:

我有一个应用程序,其中主要对象的字段具有多个日期间隔(在一个月内)。

我正在寻找一种用户友好的方式来显示在日历上标记的这些数据,并为周末和节假日提供额外的颜色。

我设法在内联模式下设置 Jquery.ui.DatePicker .. 但我找不到提供不同数据范围的方法...为周末着色并标记特定日期,如现在和自定义节假日。

$('.date-pick').datePicker({
   inline:true,
   language:'en',
   dateFormat: 'dd-mm-yy',
});

我尝试setDate ..但找不到设置间隔以及指定颜色或样式的方法。

【问题讨论】:

    标签: jquery datepicker jquery-ui-datepicker


    【解决方案1】:

    您可以针对 jQuery UI Datepicker 添加的类来更改颜色。

    周末:

    .ui-datepicker-week-end, .ui-datepicker-week-end a.ui-state-default { 
        color: Red; 
    }
    

    jQuery UI Datepicker 上周末的标记如下所示:

    <td class=" ui-datepicker-week-end " data-handler="selectDay" data-event="click" data-month="0" data-year="2015">
        <a class="ui-state-default" href="#">#DAYNUMBER</a>
    </td>
    

    对于特定日期和日期范围:

    JS

    var SelectedDates = {};
    SelectedDates[new Date("January 11, 2015")] = new Date("January 11, 2015");
    SelectedDates[new Date("January 30, 2015")] = new Date("January 30, 2015");
    
    var startDate = new Date("January 14, 2015");
    var endDate = new Date("January 21, 2015");
    
    $("input").datepicker({
       inline:true,
       language:'en',
       dateFormat: 'dd-mm-yy',
       beforeShowDay: function(date) {
            var holiday = SelectedDates[date];
            if (holiday) {
                return [true, "holiday", holiday];
            }
            else if (date >= startDate && date <= endDate) {
                return [true, 'holiday-range', holiday];
            }
            else {
                return [true, '', ''];
            }
        }
    });    
    

    CSS

    .holiday a.ui-state-default {
       background-color: Green;
       background-image: none;
       color: White;
    }
    
    .holiday-range a.ui-state-default {
       background-color: Purple;
       background-image: none;
       color: White;
    }
    

    DEMO

    参考资料:
    show weekend
    highlight specific dates

    【讨论】:

    • 看起来不错,我试试看
    • 如果您有任何问题,请告诉我。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    • 2022-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多