Set max and min datetime in jquery datetimepicker

六月ゝ 毕业季﹏ 提交于 2019-12-06 16:48:01

问题


I am using jquery datetimepicker.In which i want to set mindate and time which is the value selected in second datetimepicker.

What i tried is :

$('#date_start').datetimepicker({
        autoSize: true,
        changeYear: true,
        changeMonth: true,
        buttonImageOnly: true,
        onSelect: function (selected) {
             $('#date_end').datetimepicker("option", "minDate", selected);
        }
    });

I refered this Jquery - DateTimePicker set max datetime link.But its not a clear solution for my issue.

$('#date_end').datetimepicker({
        autoSize: true,
        changeYear: true,
        changeMonth: true,
        buttonImageOnly: true,
        onSelect: function (selected) {
            $('#date_start').datetimepicker("option", "maxDate", selected);
        }
    });

Actually this same code is working for only datepicker.But if i want it to work in datetimepicker.

What is the solution?


回答1:


In the plugin you have provided, there is no option like onSelect.

Use onSelectDate and onSelectTime or onShow,

$('#date_start').datetimepicker({
    minDate:'-1970/01/02',
    minTime:'11:00'
});

or at runtime,

var setMin = function( currentDateTime ){
  this.setOptions({
      minDate:'-1970/01/02'
  });
  this.setOptions({
      minTime:'11:00'
  });
};

$('#date_start').datetimepicker({
    onShow:setMin
});

References:

  1. minDate
  2. maxDate
  3. minTime
  4. maxTime


来源:https://stackoverflow.com/questions/38045507/set-max-and-min-datetime-in-jquery-datetimepicker

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