【问题标题】:How the jquery Datepicker set some date to highlight?jquery Datepicker如何设置一些日期来突出显示?
【发布时间】:2011-09-23 02:27:09
【问题描述】:

我现在使用 jquery Datepicker [link:http://docs.jquery.com/UI/Datepicker],如果我想设置一些日期来突出显示,而不仅仅是现在突出显示日期,我该如何设置选项?

例如:

我想突出显示 24/09/2011、25/09/2011 和 27/09/2011。

【问题讨论】:

标签: javascript jquery jquery-ui jquery-plugins


【解决方案1】:

您必须使用beforeShowDay 选项:

var dates = []; // array of the dates you want to highlight, stored as strings

$('selector').datepicker({
    beforeShowDay: function(date) {
        if ($.inArray(date.toString(), dates) != -1) {
            return [true, 'highlight'];
        }
    }
});

查看这个问题了解更多信息:

Can the jQuery UI Datepicker be made to disable Saturdays and Sundays (and holidays)?

【讨论】:

  • 参数日期,我可以将其定义为 [new Date(2011, 8, 7),new Date(2011, 8, 20)]; if ($.inArray(date, dates) != -1) .
  • @Shamrocker - 不。在 JavaScript 中,对象通过引用进行比较。例如{a:'a'} == {a:'a'} 将返回 false。为了比较您的日期,您将它们转换为字符串。使用这个:[(new Date(2011, 8, 7)).toString(), (new Date(2011, 8, 20)).toString];if ($.inArray(date.toString(), dates) != -1)
  • 非常感谢,我知道了。 :)
猜你喜欢
  • 2012-12-11
  • 1970-01-01
  • 2015-12-14
  • 2013-01-17
  • 2016-12-07
  • 1970-01-01
  • 2014-04-26
  • 2012-03-11
  • 2019-12-26
相关资源
最近更新 更多