顯示毫秒的時鐘

<!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">  
<style type="text/css">








</style>
<script type="text/javascript">  
  
var t  


  
function startTime(e)  
{  
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)  
document.getElementById("btn1").disabled=true;
document.getElementById("btn2").disabled=false;


}  
  
function checkTime(i)  
{  
if (i<10)   
  {i="0" + i}  
  return i  
}  
  
function stopCount(e)  
{  
clearTimeout(t) ;
document.getElementById("btn1").disabled=false;
document.getElementById("btn2").disabled=true;
}  
  
  
function isKeyPressed(event)  
{  
  if (event.ctrlKey==1)  
    {  
          
   startTime();  
    }  
  if(event.shiftKey==1)  
    {  
          
   stopCount()  
    }  
  }  
</script>  
</head>  
  
<body οnkeydοwn="isKeyPressed(event)">  
<form>  
<input type="button" value="開始計時!" onClick="startTime()" id="btn1">  
<input type="text" id="txt">  
<input type="button" value="停止計時!" onClick="stopCount()" id="btn2">  
</form>  
  
<p>  
請點擊上面的"開始計時"按鈕。輸入框會從 0 開始一直進行計時。點擊"停止計時"可停止計時。  
</p>  
  
</body>  
  
</html>  


謝謝bkq421511585的建議,代碼修改了下,現在按鈕不可重複提
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章