jQuery UI Datepicker被编码为始终使用类ui-state-highlight
突出显示用户的本地日期。没有内置的选项来改变这一点。
一种方法,在其他的答案相关问题的描述类似,是覆盖CSS该类以符合您的主题ui-state-default
,例如:
.ui-state-highlight {
border: 1px solid #d3d3d3;
background: #e6e6e6 url(images/ui-bg_glass_75_e6e6e6_1x400.png) 50% 50% repeat-x;
color: #555555;
}
然而,这不是,如果你非常有帮助使用动态主题,或者如果你的意图是突出不同的一天(例如,“今天”是基于你的服务器时钟而不是客户端)。
另一种方法是覆盖负责突出显示当天的日期选择器原型。
假设您正在使用UI javascript的最小化版本,以下片段可以解决这些问题。
如果你的目标是防止完全凸显当前日期:
// copy existing _generateHTML method
var _generateHTML = jQuery.datepicker.constructor.prototype._generateHTML;
// remove the string "ui-state-highlight"
_generateHtml.toString().replace(' ui-state-highlight', '');
// and replace the prototype method
eval('jQuery.datepicker.constructor.prototype._generateHTML = ' + _generateHTML);
这改变从相关的代码(处于最小化状态的可读性):
[...](printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') + [...]
到
[...](printDate.getTime() == today.getTime() ? '' : '') + [...]
如果你的目标是要改变的 “今天” 日期选择器的定义:
var useMyDateNotYours = '07/28/2014';
// copy existing _generateHTML method
var _generateHTML = jQuery.datepicker.constructor.prototype._generateHTML;
// set "today" to your own Date()-compatible date
_generateHTML.toString().replace('new Date,', 'new Date(useMyDateNotYours),');
// and replace the prototype method
eval('jQuery.datepicker.constructor.prototype._generateHTML = ' + _generateHTML);
这改变从相关的代码(处于最小化状态的可读性):
[...]var today = new Date();[...]
到
[...]var today = new Date(useMyDateNotYours);[...]
// Note that in the minimized version, the line above take the form `L=new Date,`
// (part of a list of variable declarations, and Date is instantiated without parenthesis)
而不是useMyDateNotYours
你当然也可以注入一个字符串,函数或任何适合你需要的东西。
你的代码是正确的,你可以添加一些更多的细节? – Keeper 2010-09-30 08:45:24
你有什么问题?你的代码工作正常。 [在这里看到](http://jsfiddle.net/MNBjS/) – Reigel 2010-09-30 08:46:31