JQuery UI - 根据其他timepicker值在timepicker中设置minTime

时间:2012-03-21 16:35:54

标签: jquery-ui datetimepicker jquery-ui-datepicker timepicker

我正在尝试根据我在开始时间 {中选择的内容设置结束时间 minTime的{​​{1}} { {1}}。

我有这个,基于适用于常规timepicker的东西,但它不起作用。

timepicker

我收到的错误是:

  

Object不支持此属性或方法

2 个答案:

答案 0 :(得分:1)

$('#confirmed_time_start').timepicker({
timeFormat: 'hh:mm',
stepHour: 1,
stepMinute: 15,
hour: 8,
minute: 0,
hourMin: 8,
hourMax: 18,
onSelect: function(timeStr) {

    var newTime = $(this).timepicker('getDate');
    if (newTime) { // Not null
    newTime.setDate(newTime.getDate());
    }
   $('#confirmed_time_end').timepicker('setTime', newTime);
    }

});

答案 1 :(得分:1)

var time = new Date();
$('#from').timepicker({
    ampm: true,
    hourMin: 9,
    hourMax: 19,
    timeFormat: 'hh:mm TT',
    onClose: function(dateText, inst) {
        var startDateTextBox = $('#to');
        if (startDateTextBox.val() != '') {
            var testStartDate = new Date(startDateTextBox.val());
            var testEndDate = new Date(dateText);
            if (testStartDate > testEndDate)
                startDateTextBox.val(dateText);
        }
        else {
            startDateTextBox.val(dateText);
        }
    },
    onSelect: function(dateText){
        var time = new Date($(this).datetimepicker('getDate').getTime());
        $('#to').timepicker('option', 'minDateTime',time);
    }
});
$('#to').timepicker({
    ampm: true,
    hourMin: 10,
    hourMax: 21,
    timeFormat: 'hh:mm TT',
    onClose: function(dateText, inst) {
        var startDateTextBox = $('#from');
        if (startDateTextBox.val() != '') {
            var testStartDate = new Date(startDateTextBox.val());
            var testEndDate = new Date(dateText);
            if (testStartDate > testEndDate)
                startDateTextBox.val(dateText);
        }
        else {
            startDateTextBox.val(dateText);
        }
    },
    onSelect: function(dateText){
        var time = new Date($(this).datetimepicker('getDate').getTime());
        $('#from').timepicker('option', 'maxDateTime',time);
    }
});