How to Highlight specific dates in the datepicker

守給你的承諾、 提交于 2020-01-06 08:16:45

问题


How to Highlight in BOLD specific dates in the datepicker? I have the array with dates var datesArray = new Array(); I know that I need to use beforeShowDay: method, but I can't figure it out to make it work.

This is my function:

            $(function() {
                $( "#datepicker" ).datepicker({ 
                    dateFormat: 'yy-mm-dd', 
                    onSelect: function(dateText, inst) {                             
                        dateSelected(dateText, tid) // run my function on click
                    }                     
                });
            });

回答1:


Yes you need to use beforeShowDay event, here is the test

   ...
   beforeShowDay: function(d_date){
        console.log(d_date);
        //Here compare your Date Array and the d_date
        var d_picker = new Date(d_date);
        var s_class_highligth = '';
        if($.inArray(d_picker.getDate(),a_date_array)>-1){
            s_class_highligth = 'my_cell_highligth';
        }

        return [true, s_class_highligth, 'this is optional tooltip'];
    }
    ...


来源:https://stackoverflow.com/questions/13052615/how-to-highlight-specific-dates-in-the-datepicker

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