【问题标题】:Make jquery datepicker dates a different color every year on the same dates使 jquery datepicker 每年在相同的日期日期使用不同的颜色
【发布时间】:2019-03-15 09:37:36
【问题描述】:

我想让 datepicker 日期单元格在每年的同一日期具有不同的颜色。 如果月份是 12(十二月),天是 18 到 31。 我不想要一个应该是不同颜色的特定日期数组。

我试过这个:

beforeShowDay: function(date) {
      var day = date.getUTCDate();
      var month = date.getUTCMonth();

      return [!( (day == 17 && month == 11) || (day == 18 && month == 11) || (day == 19 && month == 11) || (day == 20 && month == 11) || (day == 21 && month == 11) || (day == 22 && month == 11) || (day == 23 && month == 11) || (day == 24 && month == 11) || (day == 25 && month == 11) || (day == 26 && month == 11) || (day == 27 && month == 11) || (day == 28 && month == 11) || (day == 29 && month == 11) || (day == 30 && month == 11) )];
}

但这只会禁用单元格。我不想让它们被禁用

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 但我没有像 blueDates 数组这样的日期。它需要每年都发生。

标签: javascript jquery datepicker jquery-ui-datepicker


【解决方案1】:

您想使用 jQuery 更改全年 12 月的所有 18 到 31 日期的颜色

请检查以下代码:

$('#mydate').datepicker({
    beforeShowDay: colorize
});


function colorize(date) {
    if((date.getMonth() + 1)!=12) return [true, ""];
    if(date.getDate()<18) return [true, ""];
    
    return [true, "cool"];
}
.cool a.ui-state-default {
    background-color: #03a9f4;
    background-image: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">

<p>See December month of any year:</p>
<input type="text" id="mydate" placeholder="click here" />

【讨论】:

  • 就是这样,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-08
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 1970-01-01
  • 2016-07-09
相关资源
最近更新 更多