禁用Bootstrap 3 Datetimepicker中的未来日期

时间:2017-03-23 10:55:35

标签: javascript date datetimepicker eonasdan-datetimepicker

我使用Bootstrap 3 Datetimepicker并且我需要禁用我以后的所有日期,我知道它有自己的disabledDates功能,但我尝试了很多次并且它已经#39 ; s仍然无法正常工作。

我做错了什么?

$('#data_move').datetimepicker({
    language: 'pt-BR',
    disabledDates: [
        moment("22/02/2017")
    ]
});

2 个答案:

答案 0 :(得分:11)

您应该使用maxDate选项而不是disabledDates

这是一个工作示例:

$('#data_move').datetimepicker({
  locale: 'pt-br',
  maxDate: moment()
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/pt-br.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<div class='input-group date' id='data_move'>
  <input type='text' class="form-control" />
  <span class="input-group-addon">
    <span class="glyphicon glyphicon-calendar"></span>
  </span>
</div>

答案 1 :(得分:0)

 $('#data_move').datetimepicker({               
            maxDate: new Date
        });

试试这个就行了。