在jQuery datepicker中突出显示一周中的特定日期

我的目标是在jQuery datepicker中突出显示一周中的特定日期。

例如,我想突出周二和周四。 我已经看到了许多如何突出显示特定日期的示例(请参阅: http//jquerybyexample.blogspot.com/2012/05/highlight-specific-dates-in-jquery-ui.html )。 但不是一个能满足我需求的人。

任何提示?

强尼

您可以调整您链接的示例,以执行您想要的操作,如下所示:

CSS:

.Highlighted a{ background-color : Green !important; background-image :none !important; color: White !important; font-weight:bold !important; font-size: 12pt; } 

使用Javascript:

 $(document).ready(function() { $('#datepicker').datepicker({ beforeShowDay: function(date) { var day = date.getDay(); if (day == 2 || day == 4) { return [true, "Highlighted", date]; } return [true, '', '']; } }); });​ 

应该这样做。

如果您可以假设周在星期日开始,则可以使用+邻近选择器仅使用CSS执行此操作。 它可能看起来有点荒谬,但它可以在任何支持+:first-child (包括IE7及更高版本)的浏览器中运行。

 /* Tuesday: Su Mo Tu */ .ui-datepicker-calendar tr td:first-child + td + td a, /* Thursday: Su Mo Tu We Th */ .ui-datepicker-calendar tr td:first-child + td + td + td + td a { background:red; }​ 

演示: http : //jsfiddle.net/jnGhV/1/

这应该这样做:

 $(document).ready(function() { $('#txtDate').datepicker({ beforeShowDay: function(date) { if(date.getDay() == 2 || date.getDay() == 4) { return [true, "Highlighted", '']; } else { return [true, '', '']; } } }); });​ 

JSFiddle: http : //jsfiddle.net/XuExp/