0

我正在使用 timepicker jquery。我必须文本字段一个是从,第二个是到。所以当时间从选择自动更新时间到字段时

$('#onselectExample').timepicker();
$('#onselectExample').on('changeTime', function() {
    $('#onselectTarget').text($(this).val());
});
4

1 回答 1

1

你想改变#onselectTarget#onselectExample改变吗?它可以实现如下:

$('#onselectExample').timepicker({
    onSelect: function(selectedDateTime){
        $('#onselectTarget').text(selectedDateTime);
    }
});

如果您想在选定的时间上增加 30 分钟,您可以编写一个额外的基金:

        $(function(){
            $('#onselectExample').timepicker({
                onSelect: function(selectedDateTime){
                    console.log(selectedDateTime);
                    $('#onselectTarget').text(add30Min(selectedDateTime));
                }
            });
        });
        function add30Min(oldTime){
            var time = oldTime.split(":"); //split hours an minutes
            var hours = time[0]; // get hours
            var minutes = time[1]; // get minutes
            if (+minutes >= 30){ // when minutes over 30
                hours = (+hours+1)%24; // add an hour and convert 24 to 0
            }
            minutes = (+minutes + 30)%60; // add 30 minutes and convert 61 to 1
            return $.datepicker.formatTime('hh:mm',{ // use formatTime to return formatted Time
                'hour':hours,
                'minute':minutes
            });
        }
于 2012-10-12T09:45:59.863 回答