我有一个包含出发日期和返回日期的表格。我想在返回日期字段中设置最小日期为所选出发日期的日期。我已经将id放在div标签或input标签中,但是没有任何效果。你知道为什么吗?

<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>


这是我的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);
});

关于javascript - 如何通过Bootstrap DateTimePicker使用链接的DateTime?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48376362/

10-10 01:14