求一个JS。输入2个时间点,得出时间差。

来源:百度知道 编辑:UC知道 时间:2024/06/03 01:15:28
比如在输入框中分别输入“11:20”和“7:30”。得出时间差等于4:50(4小时50分钟)

<input id="t1" type="text" onpropertychange="formatT()" onblur="fT()" />
<input id="t2" type="text" onpropertychange="formatT()" onblur="fT()" />
<input type="button" value="计算" onclick="calc()" />
<br />
<a id="rslt"></a>
<script>
function calc()
{
try
{
var a1 = t1.value;
var a2 = t2.value;
var b1 = parseInt(a1.split(":")[0],10)*60+parseInt(a1.split(":")[1],10);
var b2 = parseInt(a2.split(":")[0],10)*60+parseInt(a2.split(":")[1],10);
rslt.innerHTML = Math.abs(parseInt((b1-b2)/60,10)) + " : " + Math.abs((b1-b2)%60);
}
catch(e){}
}
function formatT()
{
var tbox = event.srcElement;
if(tbox.va