简体   繁体   English

在动态创建的datepicker中禁用日期

[英]Disable dates in dynamically created datepicker

I am using bootstrap datepicker in my form and I just initialized bootstrap datepicker in an input field which created dynamically. 我在我的表单中使用bootstrap datepicker,我只是在动态创建的输入字段中初始化bootstrap datepicker。 The code snippet is 代码片段是

$('.editTableDatePicker').datepicker({
    format: 'mm/dd/yyyy',
    minDate: '02/19/2015',
    maxDate: '02/22/2015'
});

It shows date picker only. 它仅显示日期选择器。 It doesn't disable the dates. 它不会禁用日期。 I've tried 我试过了

$('.editTableDatePicker').datepicker({
    format: 'mm/dd/yyyy',
    startDate: '02/19/2015', // also tried setStartDate
    endDate: '02/22/2015' // also tried setEndDate
});

What I'm trying to do is to show only dates within a range. 我要做的是只显示一个范围内的日期。 For example, from 02/19/2015 to 02/23/2015. 例如,从2015年2月19日到2015年2月23日。 Can someone help me? 有人能帮我吗?

Try this: 尝试这个:

$('.editTableDatePicker').datepicker({
    format: 'mm/dd/yyyy',
    startDate: '02/19/2015',
    endDate: '02/22/2015',
});

Use startDate and endDate instead of minDate/maxDate 使用startDateendDate代替minDate/maxDate

https://bootstrap-datepicker.readthedocs.org/en/release/options.html https://bootstrap-datepicker.readthedocs.org/en/release/options.html

You have an extra comma at the end of your object, try this: 在对象的末尾有一个额外的逗号,试试这个:

$('.editTableDatePicker').datepicker({
    format: 'mm/dd/yyyy',
    startDate: '02/19/2015',
    endDate: '02/22/2015' // No comma here
});
$('#datepicker').datepicker({
    format: 'mm/dd/yyyy',
    startDate: '02/13/2015',
    endDate: '02/22/2015' 
});

Demo 演示

Insted of minDate/maxDate use startDate/endDate minDate / maxDate的insted使用startDate / endDate

  $('.editTableDatePicker').datepicker({
format: 'mm/dd/yyyy',
startDate: '02/19/2015',
endDate: '02/22/2015',

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM