Javascript 如何在 bootstrap datetimepicker 中禁用从今天开始的过去日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33915213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable past dates from today in bootstrap datetimepicker?
提问by Raviteja
Unable to disable the past dates in bootstrap datetimepicker
无法在 bootstrap datetimepicker 中禁用过去的日期
HTML
HTML
<br/>
<div class="row">
<div class="col-md-12">
<h6>Datetimepicker</h6>
<div class="form-group">
<div class="input-group date" id="datetimepicker">
<input type="text" class="form-control" /> <span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
</div>
</div>
</div>
</div>
JavaScript
JavaScript
$(function () {
$('#datetimepicker').datetimepicker();
});
I also used startDate
atrribute.But no use.
我也用过startDate
属性。但没用。
Fiddle here
在这里摆弄
回答by Shailendra Sharma
startDate
option use in bootstrap-datepickersame option not mentioned anywhere in bootstrap-datetimepicker/Options/doc it has minDate
option for that
startDate
选项在bootstrap-datepicker 中使用的相同选项在bootstrap-datetimepicker/Options/doc中的任何地方都没有提到它有这个minDate
选项
$(function () {
$('#datetimepicker').datetimepicker({
minDate:new Date()
});
});
回答by Atif Tariq
You can do it like this:
你可以这样做:
$(function () {
var date = new Date();
var today = new Date(date.getFullYear(), date.getMonth(), date.getDate());
$('#datetimepicker').datetimepicker({
minDate: today
});
});
Another solution:
另一种解决方案:
$(function () {
var date = new Date();
date.setDate(date.getDate()-1);
$('#datetimepicker').datetimepicker({
startDate: date
});
});