[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
var t www.2cto.com
function timedCount()
{
startTime();
}
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
var ms=today.getMilliseconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
ms=Math.floor(checkTime(ms)/100)
document.getElementById('txt').value=h+":"+m+":"+s+":"+ms
t=setTimeout('startTime()',100)
}
function checkTime(i)
{
if (i<10)
{i="0" + i}
return i
}
function stopCount()
{
clearTimeout(t)
}
function isKeyPressed(event)
{
if (event.ctrlKey==1)
{
startTime();
}
if(event.shiftKey==1)
{
stopCount()
}
}
</script>
</head>
<body onkeydown="isKeyPressed(event)">
<form>
<input type="button" value="開始計時!" onClick="timedCount()" >
<input type="text" id="txt">
<input type="button" value="停止計時!" onClick="stopCount()" >
</form>
<p>
請點擊上面的"開始計時"按鈕。輸入框會從 0 開始一直進行計時。點擊"停止計時"可停止計時。
</p>
</body>
</html>