【发布时间】:2014-01-30 22:00:19
【问题描述】:
再次需要您的帮助。 我没有任何代码sn-p。
以下是我的问题描述: 有两个文本框。 在一个文本框中,用户将以 24 小时格式输入任何时间,例如 23:23 或 10:12..
现在我需要根据输入的时间在第二个文本框中填充时间。 将 24 小时格式的 6 小时添加到输入的时间后,第二个文本框应显示值。即应该显示 05:23 或 16:12 等等。
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function() {
$('#new_one').on('change',function (e) {
var first_time = $(this).val();
var arr = first_time.split(':');
var hrs = arr[0];
var new_hrs = parseInt(hrs)+6;
if(new_hrs>24)
new_hrs = new_hrs-24;
if(new_hrs < 10)
new_hrs = '0'+new_hrs;
var second_time = new_hrs+':'+arr[1];
$('#new_two').val(second_time);
});
});
</script>
</head>
<body>
Text1<input type="text" id="new_one"><br/>
Text2<input type="text" id="new_two">
</body>
</html>
【问题讨论】:
-
开始解决这个问题的最佳方式是查看 JavaScript
Date对象上的文档:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… 这应该有助于您学习如何构建它功能。 -
为了帮助您,
Date对象的.getHours()方法以 24 小时格式返回小时值。 -
嗨..非常感谢..我将通过参考资料来理解这个概念。
标签: javascript jquery