新的Chrome浏览器上的Jquery datetimepicker问题

问题描述 投票:0回答:1

我已根据当前时间从datetimepicker禁用了时间。此功能适用于Windows 10 + Chrome所有版本,但不适用于Mac OS + chrome 76,78,79。

Screen with issue

working screen

$(function() {
  /* $('#datetimepicker').datetimepicker({    maxDate: new Date() ,*/

  var fivedays;
  fivedays = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() + 32);
  //fivedays = new Date(new Date().getFullYear(), new Date().getMonth()+1);

  var dt = $('#datetimepicker');

  dt.datetimepicker({
    minDate: new Date(),
    maxDate: fivedays,
    beforeShowDay: function(date) {
      if (date.getDay() > 0 && date.getDay() < 6) {
        return [true, ''];
      } else {
        return [true, ''];
      }
    },
    monthStart: new Date().getMonth(),
    monthEnd: new Date().getMonth(),
    yearStart: new Date().getFullYear(),
    yearEnd: new Date().getFullYear(),
    prevButton: true,
    nextButton: true,
    timepicker: false,
    format: 'Y/m/d',
    scrollMonth: false,
    scrollInput: false
  });

  dt.on('change', function() {
    var selectedDate = $(this).val();
    var cDate = (new Date().getFullYear()) + '/' + (new Date().getMonth()) + '/' + (new Date().getDate());
    var min = (new Date().getMinutes());
    var cTime = (new Date().getHours()) + ':' + (min.length == 1 ? '0' + min : min);

    if (new Date(selectedDate) > new Date()) {
      $('#datetimepicker3').find('option[disabled]').removeAttr('disabled');
    } else {
      $.each($('#datetimepicker3').children("option").not(':first'), function() {
        if (Date.parse(cDate + " " + $(this).attr('data-start')) <= Date.parse(cDate + " " + cTime)) {
          $(this).prop("disabled", true);
        } else {
          $(this).removeAttr("disabled");
        }
      });
    }
  });

  var dt2 = $('#datetimepicker2');
  //var dtset2 = new Date(new Date(dt).getFullYear(), new Date(dt).getMonth(), new Date(dt).getDate());

  dt2.datetimepicker({
    minDate: new Date(),
    maxDate: fivedays
      //dt2.datetimepicker({  minDate: dt, maxDate: dt
      ,
    beforeShowDay: function(date) {
      if (date.getDay() > 0 && date.getDay() < 6) {
        return [true, ''];
      } else {
        return [false, ''];
      }
    },
    monthStart: new Date().getMonth(),
    monthEnd: new Date().getMonth(),
    yearStart: new Date().getFullYear(),
    yearEnd: new Date().getFullYear(),
    prevButton: true,
    nextButton: true,
    timepicker: false,
    format: 'Y/m/d',
    scrollMonth: false,
    scrollInput: false
  });

  dt2.on('change', function() {
    var selectedDate = $(this).val();
    var cDate = (new Date().getFullYear()) + '/' + (new Date().getMonth()) + '/' + (new Date().getDate());
    var min = (new Date().getMinutes());
    var cTime = (new Date().getHours()) + ':' + (min.length == 1 ? '0' + min : min);

    if (new Date(selectedDate) > new Date()) {
      $('#datetimepicker4').find('option[disabled]').removeAttr('disabled');
    } else {
      $.each($('#datetimepicker4').children("option").not(':first'), function() {
        if (Date.parse(cDate + " " + $(this).attr('data-start')) <= Date.parse(cDate + " " + cTime)) {
          $(this).prop("disabled", true);
        } else {
          $(this).removeAttr("disabled");
        }
      });

    }
  });

  // $('#datetimepicker3').datetimepicker({ showClear: true, format: "H:i", timerangepicker:true, datepicker:false, step: 30, minTime: "7.00", maxTime: "19.00"});
  // $('#datetimepicker4').datetimepicker({ format: 'H:i', datepicker:false,  step: 30,minTime: "7.00", maxTime: "19.00"});
});
jquery jquery-ui datetimepicker
1个回答
0
投票

我发现没有问题,但是跨浏览器平台上的日期设置为其他时区,因此我没有禁用时间。

© www.soinside.com 2019 - 2024. All rights reserved.