Set minDate for Bootstrap DateTimePicker from another

▼魔方 西西 提交于 2019-12-11 13:25:22

问题


Currently, I'm using Bootstrap 3 Datepicker from this source

I have 2 datetimepicker on my system. (startTime, endTime).

I tried but don't know how to set minDate for endTime from startTime value whenever startTime value changed. Even it don't jump on change event.

Please point me what am I missing.

Here is my code

Many thanks.


回答1:


You need to use the change event and minDate() function like

$('#txtStartTime').datetimepicker({
  showTodayButton: true,
  format: 'MM/DD/YYYY HH:mm',
  sideBySide: true,
  maxDate: moment()
}).on('dp.change', function(e) {
  $('#txtEndTime').data("DateTimePicker").minDate(e.date)
});
$('#txtEndTime').datetimepicker({
  showTodayButton: true,
  format: 'MM/DD/YYYY HH:mm',
  sideBySide: true
});
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/js/bootstrap.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>


<div class="row">.</div>
<div class="col-md-3">
  <input class="form-control datetimepicker" id="txtStartTime" type='text' />
</div>

<div class="col-md-3">
  <input class="form-control datetimepicker" id="txtEndTime" type='text' />
</div>


来源:https://stackoverflow.com/questions/35713875/set-mindate-for-bootstrap-datetimepicker-from-another

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!