引导日期选择器:如何将类(例如“活动月份”)添加到我想强调的特定月份
Bootstrap datepicker: how to add class (e.g. "month active") to specific months i want to highlight
我正在使用boostrap日期选择器,我想永久突出显示特定的月份,看起来像这样:我想实现的示例。
例如,我在ShowMonth之前看到了一些方法,但我真的不明白它是如何工作的
注意:我已将日期选择器配置为仅显示月份和年份
我真的很感激所有的帮助。提前谢谢!!
var makeMonthActiveForThisYear = false;
$('.datepicker').datepicker({
format: "mm-yyyy",
viewMode: "months",
minViewMode: "months"
}).on("show", function (date) {
if (makeMonthActiveForThisYear) {
var year = parseInt($(".table-condensed thead tr th:eq(1).datepicker-switch").text().split(" ")[1]);
var highlightMonth = GetMonthToActive(year)
$('.datepicker-months table tbody tr:first td span.month').each(function () {
if ($.inArray($(this).text(), highlightMonth) > -1) {
makeMonthActiveForThisYear = false;
$(this).addClass('active');
}
});
}
}).on("changeYear", function (date) {
var highlightYear = [2015, 2014];
var year = date.date.getFullYear();
if ($.inArray(year, highlightYear) > -1) {
makeMonthActiveForThisYear = true;
}
});
function GetMonthToActive(year) {
if (year == 2014)
return ["Jan", "Feb", "Mar"];
if (year == 2015)
return ["Jan", "Mar", "Apr"];
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker3.css">
<input type="text" type="text" class="form-control datepicker" />
你可以像下面这样做。这是有效的,我在发布之前已经对其进行了测试,但如果您没有得到所需的结果,我将使用演示对其进行更新。
$('.datepicker').datepicker({
format: 'mm/dd/yyyy',
endDate: '+0d',
autoclose: true
}).on("show", function () {
var highlightMonth = ["Jan", "Feb", "Mar"];
$('.datepicker-months table tbody tr:first td span.month').each(function () {
if ($.inArray($(this).text(), highlightMonth) > -1) {
$(this).addClass('active');
}
});
});
相关文章:
- 将js添加到wordpress中以突出显示css活动菜单
- jQuery完整日历添加事件,仅包含月份和日期
- 在 JavaScript 中的个位数月份和日期之前添加零 (MM/DD/YYYY)
- 如何在非活动时间后添加随机输入
- 如何使用jQuery将当前月份添加为DIV的类
- 我正在使用php includes来构建一个多页面网站.使用jquery,我将如何添加一个类"活动的”;添加到
- Fullcalendar-我们可以将自定义数据添加到我们的活动Json数据中吗
- 在广告词脚本中添加活动选择器
- 为什么我的代码无法添加活动
- 在响应式日历中添加动态月份
- 如何制作<李>在刷新页面后添加活动的css类
- 添加活动菜单类
- 在用户滚动时为链接中的导航添加活动状态
- AngularJS:为li添加活动效果和悬停效果
- 向当前标题添加活动标题类
- 如何为Wordpress中的链接添加活动css类
- 如何使用YUI asyncRequests追溯性地向代码库添加活动AJAX请求检测
- 添加活动状态锚
- 流星和完整的日历包:我可以'不要在我的日历中添加活动
- 引导日期选择器:如何将类(例如“活动月份”)添加到我想强调的特定月份