twitter-bootstrap 引导日期选择器 js 禁用未来日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26095263/
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
bootstrap datepicker js disable future dates
提问by Karthick
I want disable future dates only on bootstrap datepicker.I had tried but can't resolve this problem.Anybody help!
我只想在引导日期选择器上禁用未来日期。我试过但无法解决这个问题。任何人都可以帮忙!
This is my code
这是我的代码
ready = function(){
$('.datepicker').datepicker({
format: 'mm-dd-yyyy',
endDate: '+0d',
autoclose: true
});
};
$(document).ready(ready);
$(document).on('page:load', ready);
回答by Ankush Jain
try the following
尝试以下
$(document).ready(function(){
$('.datepicker').datepicker({
format: 'mm-dd-yyyy',
endDate: '+0d',
autoclose: true
});
});
回答by Samuel Eli
The right thing to do is to declare a variable to hold the current date then use that in the code as the date. so below is what you need to do
正确的做法是声明一个变量来保存当前日期,然后在代码中使用它作为日期。所以下面是你需要做的
<script>
var date = new Date();
var d = new Date();
d.setDate(date.getDate());
$(document).ready(function(){
$('.datepicker').datepicker({
format: 'mm-dd-yyyy',
endDate: d,
});
});
</script>
With this, you are sure of what you want
有了这个,你确定你想要什么

