Custom text on jquery ui datepicker event

拈花ヽ惹草 提交于 2020-02-07 19:52:09

问题


I'm receiving an array from a database with some dates and a description for each day. I wish to display a jquery datepicker calendar where the specified dates are displayed with a custom css class. Besides that the user should be able to click on the specific date and get the description displayed in a different div element.

The first part with the css class is working, but I can't get the description to display. This is what I have so far:

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

var events = {};
events[new Date("09/18/2012")] = new Event("description 1", "pink");
events[new Date("09/19/2012")] = new Event("description 2", "green");

$("#minical").datepicker({
    beforeShowDay: function(date) {
        var event = events[date];
        if (event) {
            return [true, event.className, event.text];
        }
        else {
            return [true, '', ''];
        }
    },
    onSelect: function(dateText, inst) { 


    },
    minDate: "-3Y",
    maxDate: "+3Y",
    showButtonPanel: true,
    changeMonth: true,
    changeYear: true,
    altFormat: "yy-mm-dd",
    defaultDate: "+1w",
    "showButtonPanel": true
});

<style>
.pink > a { 
    background-color: pink !important;
    background-image:none !important;
}

.green > a { 
    background-color: green !important;
    background-image: none !important;
}
</style>

Thx in advance


回答1:


Im not sure if i understand your needs, but if I understand it correct, you want to display the desciption of the selected date/event in another div.

your onSelect event could be like this:

onSelect: function(dateText, inst) { 
     var event = events[new Date(dateText)];
     $("#description").html(event.text);
}


来源:https://stackoverflow.com/questions/12500841/custom-text-on-jquery-ui-datepicker-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!