尝试在按钮上单击setDatesDisabled以获取bootstrap datepicker,但它无效。
HTML:
<div id="container">
<div id="date-range">
<div class="range-start"></div>
<div class="range-end"></div>
</div>
<button id="button" class="btn btn-warning">Disable Dates</button>
</div>
JavaScript的:
$(function() {
$('#date-range').datepicker({
inputs: $('.range-start, .range-end'),
format: 'yyyy-mm-dd',
datesDisabled: ['2016-04-21', '2016-04-20', '2016-04-13']
});
$('#button').click(function() {
$('#date-range').datepicker('setDatesDisabled', ['2016-04-29', '2016-04-30']);
});
});
答案 0 :(得分:4)
初始化datepicker时使用指定的inputs
。
$(function() {
$('#date-range').datepicker({
inputs: $('.range-start, .range-end'),
format: 'yyyy-mm-dd',
datesDisabled: ['2016-04-21', '2016-04-20', '2016-04-13']
});
$('#button').click(function() {
$('.range-start').datepicker('setDatesDisabled', ['2016-04-29', '2016-04-30']);
$('.range-end').datepicker('setDatesDisabled', ['2016-04-29', '2016-04-30']);
});
});