Highlight dates in jquery UI datepicker

前端 未结 6 2000
暖寄归人
暖寄归人 2020-12-08 03:04

How i can use beforeShowDay for highlighting days in jQuery UI datepicker. I have the following date array

Array
(
    [0] => 2011-07-07
         


        
6条回答
  •  余生分开走
    2020-12-08 03:45

    Dates in JS are instances of object Date, so you can't check properly if dates are equal using == or ===.

    Simple solution:

    var your_dates = [
       new Date(2017, 4, 25),
       new Date(2017, 4, 23)
    ];
    
    $( "#some_selector" ).datepicker({
        beforeShowDay: function(date) {
            are_dates_equal = d => d.getTime() === date.getTime();
            if(your_dates.some(are_dates_equal)) {
                return [true, 'ui-state-active', ''];
            }
            return [true, '', ''];
        }
    })
    

提交回复
热议问题