本文介绍了具有Bootstrap Datetimepicker的defaultDate和minDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将选择器默认设置为未来一个月.效果很好:

I want a picker to be set to a month in the future by default. This works fine:

<script type="text/javascript">
  $(function () {
    $('#enddatepicker').datetimepicker({
      defaultDate: moment().add(1, 'M').toDate(),
      locale: 'de',
      format: 'DD.MM.YYYY'
    });
  });
</script>

但是,我也希望日期不早于明天.因此,我尝试添加minDate选项:

However, I also want the date to be not before tomorrow. So I try adding a minDate option:

<script type="text/javascript">
  $(function () {
    $('#enddatepicker').datetimepicker({
      minDate: moment().add(1, 'd').toDate(),
      defaultDate: moment().add(1, 'M').toDate(),
      locale: 'de',
      format: 'DD.MM.YYYY'
    });
  });
</script>

但是,现在默认日期设置为minDate(即明天).我可以独立于最小日期设置默认日期吗?

However, now the default date is set to minDate (that is, tomorrow). Can I set a default date independently from the minimum date?

推荐答案

查看 GitHub (第1674行),如果您设置了选项 useCurrent 设置为false,则您的默认设置可能不会被覆盖:

Looking at the code on GitHub (line 1674) if you set the option useCurrent to false, your default may not be overridden:

 <script type="text/javascript">
   $(function () {
     $('#enddatepicker').datetimepicker({
       useCurrent: false,
       minDate: moment().add(1, 'd').toDate(),
       defaultDate: moment().add(1, 'M').toDate(),
       locale: 'de',
       format: 'DD.MM.YYYY'
     });
   });
 </script>

这篇关于具有Bootstrap Datetimepicker的defaultDate和minDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 23:39