jQuery UI日历显示onLoad上的事件

时间:2012-04-17 16:12:35

标签: javascript jquery-ui datepicker

我有一个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++;
    }
}
});

1 个答案:

答案 0 :(得分:1)

当然,加上这个:

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

<强> jsFiddle example