【发布时间】:2013-09-05 16:00:45
【问题描述】:
我正在尝试使用带有 MySQL 数据库的 Jquery datepicker 来显示任何有事件的日期。
出于偏好,我设置了 showOtherMonths: true。
我想做的是设置当月禁用日期的样式,使它们与其他月份的日期颜色不同。
我怎样才能为此添加样式?
$(document).ready(function()
{
var selected_dates = new Array();
// get all the events from the database using AJAX
selected_dates = getSelectedDates();
$('#datepicker').datepicker({
dateFormat: 'yy-m-d',
inline: true,
showOtherMonths: true,
dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
beforeShowDay: function (date)
{
// get the current month, day and year
// attention: the months count start from 0 that's why you'll need +1 to get the month right
var mm = date.getMonth() + 1,
dd = date.getDate(),
yy = date.getFullYear();
var dt = yy + "-" + mm + "-" + dd;
if(typeof selected_dates[dt] != 'undefined')
{
// put a special class to the dates you have events for so you can distinguish it from other ones
// the "true" parameter is used so we know what are the dates that are clickable
return [true, " my_class"];
}
return [false, ""];
}
});
});
【问题讨论】:
标签: jquery css jquery-ui-datepicker