2

我想让 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) )];
}

但这只会禁用细胞。我不想让他们禁用

4

1 回答 1

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" />

于 2018-10-10T13:18:26.273 回答