突出显示boostrap嵌入式/内联日期选择器的特定日期

时间:2017-06-09 10:08:04

标签: jquery datepicker

如何在boostrap嵌入/内联日期选择器上突出显示特定日期?

我试过了:

$(document).ready(function () { 
    $('#datepicker').datepicker({
        format: "dd/mm/yyyy",
        minDate:new Date(),
        startDate: "now"
    });
});

HTML:

<div id="datepicker"></div>

1 个答案:

答案 0 :(得分:0)

您可以使用beforeShowDay突出显示特定日期,如下所示。

Working fiddle

var active_dates = ["16/6/2017"]; // Highlite date
$('#datepicker').datepicker({

  beforeShowDay: function(date) {
    var d = date;
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //Months are zero based
    var curr_year = d.getFullYear();
    var formattedDate = curr_date + "/" + curr_month + "/" + curr_year;
    if ($.inArray(formattedDate, active_dates) != -1) {
      return {
        classes: 'highlight'
      };
    }
    return;
  }
});