使用jquery在开始时间上增加一小时 [英] Add one hour onto start time using jquery

查看:524
本文介绍了使用jquery在开始时间上增加一小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文本框.一个是开始时间,另一个是结束时间.当用户在开始时间中输入时间时,如何自动在结束时间框中添加一小时?

这些值是字符串,并且不具有time的数据类型.我真的在互联网上找不到有关如何执行此操作的任何信息.

I have two textboxes. One is for a start time and the other is an end time. How can I add one hour to the end time box automatically when a user enters a time in the start time?

The values are strings and do not have a datatype of time. I really cannot find anything on the internet on how to go about doing this.

示例
Start time: <input type="text" id="startTime" />
End time: <input type="text" id="endTime" />

Example
Start time: <input type="text" id="startTime" />
End time: <input type="text" id="endTime" />

如果用户在startTime中输入14:00,我需要它以15:00自动填充endTime.

If the user enters 14:00 in startTime, I need it to automatically populate endTime with 15:00.

关于如何做到这一点的任何想法?谢谢.

Any ideas on how this can be done? Thanks you.

推荐答案

考虑到上述评论,我认为这应该对您有用和您的要求

$('#startTime').keyup(function(){
    if(/[0-9]{2}\:[0-9]{2}/.test($(this).val())){
        var startTime = $(this).val().split(':');
        var endHours = parseInt(startTime[0]) +1;
        endHours = Math.min(Math.max(endHours, 1), 24);
        $('#endTime').val(endHours +':'+ startTime[1]);
    }
});

这篇关于使用jquery在开始时间上增加一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆