假设我希望2011年5月2日(或任何其他日子)与其他日子颜色不同.这可能吗?
这是特定日期的示例项目
<td class=" " onclick="DP_jQuery_1305738227207.datepicker._selectDay('#datepicker',4,2011,this);return false;"><a class="ui-state-default ui-state-hover" href="#">11</a></td>
我不知道是否有任何方法可以覆盖datepicker如何为每天创建id /类.
解决方法
工作实例:
http://jsfiddle.net/hunter/UBPg5/
您可以通过添加beforeShowDay回调来完成此操作
绑定你的回调:
$("input:text.date").datepicker({ beforeShowDay: SetDayStyle });
var badDates = new Array("5/2/2011"); function SetDayStyle(date) { var enabled = true; var cssClass = ""; var day = date.getDate(); var month = date.getMonth() + 1; //0 - 11 var year = date.getFullYear(); var compare = month + "/" + day + "/" + year; var toolTip = badDates.indexOf(compare) + " " + compare if (badDates.indexOf(compare) >= 0) cssClass = "bad"; return new Array(enabled,cssClass,toolTip); }
创建你的风格
.bad { background: red; } .bad a.ui-state-active { background: red; color: white; }
http://jqueryui.com/demos/datepicker/#event-beforeShowDay
The function takes a date as a parameter and must return an array with [0] equal to true/false indicating whether or not this date is selectable,[1] equal to a CSS class name(s) or ” for the default presentation,and [2] an optional popup tooltip for this date. It is called for each day in the datepicker before it is displayed.