JavaScript:jQuery Datepicker – 特定日子的简单突出显示,谁可以提供帮助? (来源)

我想使用Datepicker突出显示特定日期。 这是我最新的代码:

 var dates = [30/04/2010, 01/05/2010]; $(function(){ $('#datepicker').datepicker({ numberOfMonths: [2,3], dateFormat: 'dd/mm/yy', beforeShowDay: highlightDays }); function highlightDays(date) { for (var i = 0; i < dates.length; i++) { if (dates[i] == date) { return [true, 'highlight']; } } return [true, '']; } });  

我的CSS是:

 #highlight, .highlight { background-color: #cccccc; } 

好了,日历出现了,但没有突出显示。 我的代码中的问题在哪里? 如果有人能提供帮助,那就太好了。

另一个选项/解决方案可能是:禁用所有日期,但仅使数组中的日期可用。

谢谢!

让我们告诉你一些问题……

1。 var dates = [30/04 / 2010,01 / 05/2010];

不会按预期存储你的日期……它会做数学运算……

2.将其更改为字符串,但格式为: mm/dd/yy
所以,你应该有类似的东西:

 var dates = ['04/30/2010', '05/01/2010']; 

3.使用此function:

 function highlightDays(date) { for (var i = 0; i < dates.length; i++) { if (new Date(dates[i]).toString() == date.toString()) { return [true, 'highlight']; } } return [true, '']; } 

4. CSS为:

 td.highlight { background-color: red; border: 1px blue solid; } 

5. 演示

时区有问题。

 function highlightDays(date) { for (var i = 0; i < dates.length; i++) { if (new Date(dates[i]).toString().substr(0, 16) == date.toString().substr(0, 16)) { return [true, 'highlight']; } } return [true, '']; }