bootstrap datetimepicker阻止minDate打印

时间:2016-07-26 10:46:23

标签: jquery twitter-bootstrap bootstrap-datetimepicker eonasdan-datetimepicker

我正在使用bootstrap datetimepicker,这是我的脚本

$('.start_datetime, .end_datetime').datetimepicker({
    format: 'YYYY-MM-DD HH:mm:ss',
    inline:false,
    ignoreReadonly: true,
    allowInputToggle: true,
    sideBySide:true,
    minDate: new Date()
});

在上面的脚本中,我将minDate初始化为今天的日期,但问题是当我今天查看结果时,日期已经作为文本框的打印值而来了但我没有&# 39;我希望它被打印我希望它只是限制它选择日期之前的日期。

1 个答案:

答案 0 :(得分:2)

选择器显示今天的日期,因为默认情况下useCurrent选项为true,如documentation中所述。

useCurrent设置为false将解决您的问题,如以下代码所示:



$('.start_datetime, .end_datetime').datetimepicker({
    format: 'YYYY-MM-DD HH:mm:ss',
    inline: false,
    ignoreReadonly: true,
    allowInputToggle: true,
    sideBySide:true,
    minDate: new Date(),
    useCurrent: false
});

<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.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.13.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>

<div class="form-group">
  <div class="input-group date start_datetime">
    <input type="text" class="form-control" />
    <span class="input-group-addon"><span class="glyphicon-calendar glyphicon"></span></span>
  </div>
</div>
&#13;
&#13;
&#13;