0

我有一个 jQuery UI DatePicker 日历,alerts当单击具有事件的日期时。 http://jsfiddle.net/helpinspireme/DuwZL/ 我想添加的是加载中,如果今天有事件,我希望在加载日历时显示警报。任何帮助将不胜感激。谢谢你。

var events = [ 
{ Title: "Meeting with boss", Date: new Date("04/13/2012") },
{ Title: "Meeting with manager", Date: new Date("04/13/2012") },
{ Title: "Five K for charity", Date: new Date("04/17/2012") }, 
{ Title: "Dinner", Date: new Date("04/25/2012") }
];

$("div").datepicker({
beforeShowDay: function(date) {
    var result = [true, '', null];
    var matching = $.grep(events, function(event) {
        return event.Date.valueOf() === date.valueOf();
    });

    if (matching.length) {
        result = [true, 'highlight', null];
    }
    return result;
},
onSelect: function(dateText) {
    var date,
        selectedDate = new Date(dateText),
        i = 0,
        event = null;

    while (i < events.length) {
        date = events[i].Date;

        if (selectedDate.valueOf() === date.valueOf()) {
            event = events[i];
            alert(event.Title);
        }
        i++;
    }
}
});

​</p>

4

1 回答 1

1

当然,添加这个:

$('.ui-datepicker-today').trigger('click');

jsFiddle 示例

于 2012-04-17T16:35:45.167 回答