【问题标题】:jquery datepicker highlight weekend daysjquery datepicker 突出显示周末
【发布时间】:2016-07-05 14:17:04
【问题描述】:

我有一个用于 web 应用程序的 Jquery 日期选择器,我的问题是:我想在需要时同时突出显示 2 天。这仅适用于周末

当我选择星期六时,星期天必须突出显示(添加一个名为“ui-native-asive”)的类,对于星期日,周日选择时,星期六也必须突出显示。

beforeShowDay: function(d) {
    var selecteddate =  $( ".datepicker" ).datepicker( "getDate" );
    var day = selecteddate.getDay();

    if (day == 6) { // day 6 = saturday      
       // Now saturday must get the class highlight
       return [true, 'highlight'];
    }
    else if (day == 0){ // day 0 = sunday 
       // Now sunday must get the class highlight
       return[true, 'highlight']; 
    }

}

问候 丹尼斯

【问题讨论】:

  • 您尝试过什么吗?您当前的代码是什么?
  • @JacquesMarais I've searched for the internet and tried the example above I posted, but I can't trigger the other day when one day is selected and can't find anything in common of this.
  • “突出显示”是什么意思?是否也要将值设置为第二天?
  • @JacquesMarais yep, when one day is selected, it has the class "ui-state-active", so then I want that class too on the Saturday or Sunday, based on the selected day.
  • 请编辑您的帖子以包含该信息

标签: javascript jquery datepicker


【解决方案1】:

您需要为日期选择器实现beforeShowDay 事件:

该函数将日期作为参数,并且必须返回一个数组 [0] 等于真/假,表示此日期是否为 可选择的,[1] 等于 CSS 类名或默认为 '' 演示文稿,以及 [2] 此日期的可选弹出工具提示。它是 日期选择器中的每一天在显示之前调用。

所以你需要做类似的事情:

$("#datepicker").datepicker({
    beforeShowDay: function(d) {
        //check if it's Sunday then highlight Saturday and vice versa.
    }
});

【讨论】:

  • 见上面编辑过的问题。这就是我现在所拥有的,但我不知道如何安排另一天的课程。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-06
  • 2012-12-11
  • 2012-03-11
  • 1970-01-01
  • 2013-09-06
  • 2013-05-29
  • 1970-01-01
相关资源
最近更新 更多