Style weeks using the Bootstrap Datepicker

烈酒焚心 提交于 2019-12-12 03:57:50

问题


I'm using the bootstrap datepicker and suppose I wish to apply styles to the calendar that appear when the calendar opens:

  1. Highlight 3/1/17 3/7/17 red
  2. Highlight 3/9/17 3/17/17 blue

How can I use CSS to do this? Is there a feature in the API that allows for this?


回答1:


There is no direct API for this feature, but you can use option debug: true to inspect component HTML.

One way to target a specific day is using a CSS selector based on data-day attribute value, for example: [data-day="03/01/2017"]. Here a full live example:

$('#datetimepicker1').datetimepicker({
  debug: true
});
[data-day="03/01/2017"], [data-day="03/07/2017"]{
  background-color: red;
}

[data-day="03/09/2017"], [data-day="03/17/2017"]{
  background-color: blue;
}
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<div class="input-group date" id="datetimepicker1">
  <input type="text" class="form-control" />
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>

Here you can find a similar example.



来源:https://stackoverflow.com/questions/42380550/style-weeks-using-the-bootstrap-datepicker

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