twitter-bootstrap Bootstrap Datepicker 无法设置开始/结束日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17797164/
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 unable to set start/end dates
提问by Wes
Here is code:
这是代码:
<input type="text" class="datepicker" id="flight_start" placeholder="mm-dd-yyyy" data-date-format="mm-dd-yyyy">
...
<script src="/ui/js/jquery.js"></script>
<script src="/ui/js/bootstrap.js"></script>
<script src="/ui/js/datatables/jquery.dataTables.min.js"></script>
<script src="/ui/js/datatables/DT_bootstrap.js"></script>
<script src="/ui/js/responsive-tables/responsive-tables.js"></script>
<script src="/ui/js/datepicker/date.js"></script>
<script src="/ui/js/datepicker/daterangepicker.js"></script>
<script src="/ui/js/chosen/chosen.jquery.js"></script>
<script src="/ui/js/bootstrap-wizard/bootstrap-wizard.js"></script>
<script src="/ui/js/sparkline/jquery.sparkline.min.js"></script>
<script src="/ui/js/datepicker/bootstrap-datepicker.js"</script>
...
<script type="text/javascript">
$('#flight_start').datepicker({
format: "mm-dd-yyyy",
startDate: "+1d"
});
</script>
The format works, but not the start date. I get no errors/warnings, simply does not work. Dates prior to the start date are not grayed out in any way and can be selected. I want to remove this ability. Thanks!
格式有效,但开始日期无效。我没有收到错误/警告,只是不起作用。开始日期之前的日期不会以任何方式变灰并且可以选择。我想移除这个能力。谢谢!
Edit: I've also tried
编辑:我也试过
$('#flight_start').datepicker('setStartDate', '+1d');
Which gives me
这给了我
Uncaught TypeError: Object [object Object] has no method 'setStartDate'
采纳答案by Wes
Looks like the problem was I had an out of date version of bootstrap-datepicker.js.
看起来问题是我有一个过时的 bootstrap-datepicker.js 版本。
A coworker just picked up the plugin so I'm not sure why he downloaded an out of date version, oh well.
一位同事刚刚拿起了插件,所以我不确定他为什么下载了一个过时的版本,哦,好吧。
回答by Usman Younas
Try this code, worked for me. disabled dates prior to today
试试这个代码,对我有用。今天之前的禁用日期
$("YOURSELECTOR").datepicker({
format: 'dd/mm/yyyy',
startDate:new Date()
});
Remember this is bootstrap picker
记住这是引导选择器
回答by vinod
<script type="text/javascript">
$(function () {
$('#flight_start').datepicker({
format: "mm-dd-yyyy",
startDate: "04-07-2010",
endDate: "04-07-2014"
});
});
</script>
回答by Mike Robinson
Needs a document.ready
需要文件。准备好了
<script type="text/javascript">
$(function () {
$('#flight_start').datepicker({
format: "mm-dd-yyyy",
startDate: "+1d"
});
});
</script>
回答by asifaftab87
I did like this, For end date
我喜欢这个,对于结束日期
$("#yourDateFieldId").datepicker('setEndDate', (new Date().getDate())+"-"+(new Date().getMonth()+1)+"-"+new Date().getFullYear());
For start date
对于开始日期
$("#yourDateFieldId").datepicker('setStartDate', "01-01-2000");

