简体   繁体   English

如何通过Bootstrap DateTimePicker使用链接的DateTime?

[英]How to use linked DateTime using Bootstrap DateTimePicker?

I have a form which contains Departure date and return date. 我有一个包含出发日期和返回日期的表格。 And I want to set the minimum date in the return date field is the date of selected departure date. 我想在返回日期字段中设置最小日期为所选出发日期的日期。 I already put the id in div tag or input tag, but nothing worked. 我已经将id放在div标签或input标签中,但是没有任何效果。 Do you know why? 你知道为什么吗?

<div class="form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">Departure<span class="required"> *</span></label>
    <div class="input-group date form_datetime col-md-4 col-sm-4 col-xs-12" id="res_departure1" data-link-field="dtp_input1">
        <input class="form-control pull-right" size="16" type="text" value="" readonly required>
        <input type="hidden" id="dtp_input1"  name="res_departure" value="" />
        <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
    </div>
</div>
<div class="form-group">
    <label class="control-label col-md-3 col-sm-3 col-xs-12">Return<span class="required"> *</span></label>
    <div class="input-group date form_datetime col-md-4 col-sm-4 col-xs-12" id="res_return1" data-link-field="dtp_input2">
        <input class="form-control pull-right"  size="16" type="text" value="" readonly required>
        <input type="hidden" id="dtp_input2" name="res_return" value="" />
        <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
      </div>
</div>

This is my js 这是我的js

$('.form_datetime').datetimepicker({
    //language:  'fr',
    format: "yyyy-mm-dd hh:ii",
    autoclose: true,
    todayBtn: true,
    startDate: new Date
});

$("#res_departure1").on("dp.change", function (e) {
    $('#res_return1').data("DateTimePicker").setMinDate(e.date);
});
$('#res_departure1').datetimepicker().on('changeDate', function(ev) {
    var departureDate = ev.date;
    $('#res_return1').datetimepicker('setStartDate', departureDate);
});

$('#res_return1').datetimepicker().on('changeDate', function(ev) {
    var returnDate = ev.date;
    $('#res_departure1').datetimepicker('setEndDate', returnDate);
});

Try this instead of your code 试试这个代替你的代码

$('.form_datetime').datetimepicker({
    //language:  'fr',
    format: "yyyy-mm-dd hh:ii",
    autoclose: true,
    todayBtn: true,
    startDate: new Date()
});

$("#res_departure1").on("dp.change", function (e) {
   $('#res_return1').data('DateTimePicker').minDate(new Date(e.timeStamp));
});

Because when you are talking about date only, then better to use datepicker on jQuery ui library, and then you can use the onSelect event of the departure date and then set the min date of return field. 因为仅在谈论日期时,最好在jQuery ui库上使用datepicker ,然后可以使用出发日期的onSelect事件,然后设置返回日期的最小日期字段。

  onSelect: function(selectedDate)
  {
    $('#return').datepicker('option', 'minDate', selectedDate);
  }

you can check the working fiddle here. 您可以在这里查看工作提琴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未将日期时间值设置为引导程序 DatetimePicker - Not Set Datetime Value To The Bootstrap DatetimePicker 如何正确使用引导日期时间选择器区域设置选项 - How to use bootstrap datetimepicker locale option properly 如何在bootstrap datetimepicker js文件中的日期时间选择器中设置先前的日期 - How to diasable previous date in datetime picker in bootstrap datetimepicker js file bootstrap datetimepicker返回字符串,如何将该字符串转换为datetime(php) - bootstrap datetimepicker retuns a string, how to convert this string into datetime (php) 如何使用Bootstrap DateTimePicker筛选Bootstrap表中的日期? - How to use bootstrap datetimepicker to filter dates in bootstrap table? 如何禁用 Bootstrap 日期时间选择器 - How to disable Bootstrap datetimepicker 如何使用Bootstrap日期时间控件 - How to use Bootstrap datetime control 如何在多个动态创建的输入上使用Bootstrap Datetimepicker - How to use Bootstrap Datetimepicker on multiple dynamically created inputs 如何使用datetimepicker插件格式化datetime? - How to format datetime with the datetimepicker plugin? 如何使用bootstrap datetimepicker获取三个月后的日期? - How to get date of after three month using bootstrap datetimepicker?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM