开发者

Highlighting Events in a Jquery Datepicker

开发者 https://www.devze.com 2023-02-24 22:21 出处:网络
I am trying to highlight ev开发者_JAVA百科ents in a datepicker, but I cannot get it working. The events are in the calender (when I click on them all functionality is correct) just not highlighted. He

I am trying to highlight ev开发者_JAVA百科ents in a datepicker, but I cannot get it working. The events are in the calender (when I click on them all functionality is correct) just not highlighted. Here is how I attempt to highlight them:

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

        if (matching.length) {
            //Adds highlight to day
            result = [true, 'highlight', null];
        }
        return result;
    },

Any suggestions?


The way that you are using your var result variable is potentially quite risky.

This JSFiddle will show you how this is a problem. Click 'Click1' and it will alert ok, but clicking 'Click2' will alert nothing.

Declare the variable outside of your anonymous function function (date) {, i.e.

    var result = [true, '', null];

    beforeShowDay: function (date) {
        var matching = $.grep(events, function (event) {
        return event.Date.valueOf() === date.valueOf();
    });

    if (matching.length) {
        //Adds highlight to day
        result = [true, 'highlight', null];
    }
    return result;
},


Your Script should work, just as debugging step, check the output, does the class: "highlight" being really added on the tags? to make sure of this, inspect the elements. make sure you have added a class highlight to the css.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号