提问者:小点点

从开始时间起15分钟自动填充完成时间文本框


我有两个textbox,start_timefinish_time,当我使用jquery时间选择器选择时间时,可以说是12:00:00,完成时间应该自动显示为12:15:00。有什么帮助吗?非常感谢。我尝试了很多javascript代码,但都不起作用。im使用24小时格式。

<html>
            
           <div>
           <input  type="text" name="start_time" id="start_time"> 
           <div>
           
            <div>
         <input  type="text" name="finish_time" id="finish_time" readonly>
         </div>
      </html>

共1个答案

匿名用户

这个插件将选择的时间存储在列表中,准确地说,存储在ID为#ui-active-item的元素中。当你知道这一点时,只剩下一些时间操纵。

$(document).ready(function() {
    $('#start_time').timepicker({
        timeFormat: 'HH:mm ss',
        interval: 1,
        minTime: '10',
        maxTime: '6:00pm',
        defaultTime: '11',
        startTime: '10:00',
        dynamic: false,
        dropdown: true,
        scrollbar: true
    });
    $('#start_time').blur(function() {
        console.log($('#ui-active-item').text());
        time = new Date($('#ui-active-item').text());
        final = new Date(time.getTime() + 15 * 60000);
        timer = final.toLocaleTimeString('it-IT')
        $('#finish_time').val(timer)
    })
});

演示:

null

$(document).ready(function() {
    $('#start_time').timepicker({
        timeFormat: 'HH:mm ss',
        interval: 1,
        minTime: '10',
        maxTime: '6:00pm',
        defaultTime: '11',
        startTime: '10:00',
        dynamic: false,
        dropdown: true,
        scrollbar: true
    });
    $('#start_time').blur(function() {
        console.log($('#ui-active-item').text());
        time = new Date($('#ui-active-item').text());
        final = new Date(time.getTime() + 15 * 60000);
        timer = final.toLocaleTimeString('it-IT')
        $('#finish_time').val(timer)
    })
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>

<input  type="text" name="start_time" id="start_time"> 
<input  type="text" name="finish_time" id="finish_time" readonly>