Is there a way to style jquery's datepicker days?

你说的曾经没有我的故事 提交于 2019-11-30 20:05:53

Working Example: http://jsfiddle.net/hunter/UBPg5/


You can do this by adding a beforeShowDay callback

Bind your callback:

$("input:text.date").datepicker({
    beforeShowDay: SetDayStyle
});

Create your function with some static array of bad dates or construct this array somewhere else:

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);
}

Create your styles

.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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!