【发布时间】:2015-08-18 21:04:58
【问题描述】:
我正在尝试使用选项 datesDisabled 禁用日期选择器中的月份。根据文档,它应该通过以我用于日期选择器的格式传递一个字符串数组来工作,但我无法让它工作。
HTML:
<div class="modal-body">
<div class="input-append date" id="datepicker1" data-date="Aug-2015" data-date-format="mm-yyyy" data-dates-disabled="Sep-2015,Oct-2015" style="display:inline-block; font-weight:bold;">
Check In: <input type="text" readonly="readonly" name="date1" >
<span class="add-on"><i class="glyphicon glyphicon-calendar"></i></span>
</div>
</div>
Javascript:
var dateStart = new Date();
dateStart.setDate(dateStart.getDate()-1);
$( document ).ready(function() {
var dp = document.getElementById("datepicker1");
$("#datepicker1").datepicker( {
format: "mm-yyyy",
startView: "months",
minViewMode: "months",
startDate: dateStart,
datesDisabled: dp.dataset.datesDisabled.split()
}).datepicker("setDate",null);
});
更新:
看起来这不会得到答复,所以我决定尝试通过查找所有月份并将它们更改为残疾人课程来做到这一点。问题是我无法检测到能够获取当前日历年份的点击。
日期选择器标头的 HTML:
<tr>
<th style="visibility: hidden;" class="prev">«</th>
<th colspan="5" class="datepicker-switch">2015</th>
<th style="visibility: visible;" class="next">»</th>
</tr>
Javascript:
$("th.next:first").click(function(){
var currentYear = $("th.datepicker-switch:first").html();
console.log("current year is " + currentYear); // nothing happens here
});
检测日期选择器内元素点击的正确方法是什么?
【问题讨论】:
-
我检查了你的 Fiddle 并且 2015 年 9 月和 2015 年 10 月仍然启用?
-
哦。我没有检查。将在一段时间内更新小提琴。现在有点忙
-
好的,所以我一直在努力解决您的问题,但我遇到了困难。我看到您已经更新了您的问题,并且您正在寻找一种方法来检测日期选择器中的点击事件。您可以使用
changeDate事件。试试这个.on('changeDate', function (ev) { console.log(ev); }); -
更新了@Sushil fidlde --> jsfiddle.net/SantoshPandu/z2v31Leo/2
标签: jquery twitter-bootstrap datepicker