我正在使用两个datetimepicker Bootstrap,第一个是startDate,第二个是enddate,问题是我应该选择开始日期,并且在结束日期中自动选择最小日期(我在开始日期中选择的日期)。并且终止日期的datatimepicker中日期的最大值为+7天。你能帮我吗?

我试图在名为datatimepicker6的第一个datatimepicker中获取日期,但确实做到了,但我不知道如何在称为datatimepicker7的结束日期datatimepicker中使用。下面是代码:

//these part is to pick the date and it work
$("#datetimepicker6").on("dp.change", function(e) {
    var drr = $('#datetimepicker6').data('date')
    alert(drr);
});
      $('#datetimepicker6').datetimepicker({
        format: 'DD.MM.YYYY HH:mm:ss',

        keyBinds: {'delete': null}
      });

//I want to use that result as the minimum of this datatimepicker and to add +7 days as maximum

      $('#datetimepicker7').datetimepicker({
        format: 'DD.MM.YYYY HH:mm:ss',
        //useCurrent: false,
      //maxDate: drr,
        keyBinds: {'delete': null},


        useCurrent: false //Important! See issue #1075
      });

最佳答案

将此添加到您的onchange事件中,它将起作用

            e.date.add(7, 'day');
            $('#datetimepicker7').data("DateTimePicker").minDate(e.date);
            $('#datetimepicker7').data("DateTimePicker").date(e.date);


完整代码onchange

 $("#datetimepicker6").on("dp.change", function (e) {
         //var val = $('#datetimepicker6').data('date');
        e.date.add(7, 'day');
    $('#datetimepicker7').data("DateTimePicker").minDate(e.date);
   $('#datetimepicker7').data("DateTimePicker").date(e.date);

                });
            });


check the demo here

关于javascript - 在函数内获取值以在函数外使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55626103/

10-15 21:44