1

我发现了这个 datepicker 事件,但不适用于 IE。我不知道这段代码有什么问题。

var Event = function(text, className) {
        this.text = text;
        this.className = className;
    };


var events = {};
events[new Date("18/Jan/2013")] = new Event("Drinks @ Seymours - Alumni Event", "Yes");
events[new Date("16/Jan/2013")] = new Event("Retired Staff Luncheon", "Yes");
events[new Date("13/Jan2013")] = new Event("October Spring Lunch - Alumni Event", "Yes");


$("#dates").datepicker({
    dateFormat: 'dd/M/yy',  
    firstDay: 1,
    showOtherMonths: true,
    onSelect: function(date) {
        $('#CAT_Custom_241423').val(date);
        $('#submit-btn-webapp').trigger('click');
    },
    beforeShowDay: addClass 
});

function addClass(date) { 
    var event=events[date];
    if(event){
        return[true,event.className,event.text];
    }
    else {
        return[true,'',''];
    }
}

它在 ff,Google Chrome 上运行良好。这是 jsfiddle 上的工作代码

http://jsfiddle.net/7U56z/

4

1 回答 1

0

问题是事件键(生成的日期)。如果您在 IE 中尝试以下操作:

 alert(new Date("18/Jan/2013"));

你会得到一个错误(无效的日期)。所以你永远不会在你的函数中得到匹配。像这样定义键(或与此类似):

 events[(new Date(2013, 0, 18, 0, 0, 0))] = new Event(....)
 // format in this case is:
 // new Date(year,month,day,hour,minute,second)
 // month starts with 0.

它有效。在这种情况下,您不必设置小时、分钟和秒。您只需确保生成的密钥是有效日期并且与来自日期选择器的日期匹配。

By the way, I would rename your "Event" Object to something different, because there is already an window.event that is a bit confusing.

于 2013-01-27T13:52:47.020 回答