且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在引导日期选择器中突出显示特定日期?

更新时间:2023-01-29 18:47:52

如amphetamachine所建议在bootstrap-datepicker上突出显示某些日期提供了解决此问题所需的大部分方法.该问题的答案可以适应以下情况

As suggested by amphetamachine Highlight certain dates on bootstrap-datepicker provides most of what is required to solve this. The answer to that question can be adapted to the following

$('.inline_date').datepicker({
    multidate: true,
    todayHighlight: true,
    minDate: 0,
    beforeShowDay: function(date) {
       var hilightedDays = [1,3,8,20,21,16,26,30];
       if (~hilightedDays.indexOf(date.getDate())) {
          return {classes: 'highlight', tooltip: 'Title'};
       }
    }
});

以上内容将突出显示样式类应用于每月列出的日期,进一步检查您可以将其限制为特定月份.某些旧的浏览器可能不支持indexOf,在这种情况下,您可以使用JS库或扩展if.

The above will apply the highlight style class to the listed days in every month, with further checks you could limit it to specific months. Some old browsers may not support indexOf, in which case you can either use a JS library or expand the if.