JS 实现时钟表

<html>
<head>
<title>时间表</title>
<script type="text/javascript">
function startTime(){
 var today=new Date();
 var h=today.getHours();
 var m=today.getMinutes();
 var s=today.getSeconds();
 m=checkTime(m);
 s=checkTime(s);
 document.getElementById("txtMes").innerHTML=h+":"+m+":"+s;
 setTimeout("startTime()",1000);
}
function checkTime(vari){
 if(vari<10){
  vari="0"+vari;
 }
 return vari;
}
window.onload=function(){
 startTime();
}
</script>
</head>
<body>
<div id="txtMes" style='color:red; background:#eee;'></div>
</body>
</html>
posted @ 2012-11-05 17:56  永不言败,自信相伴  阅读(124)  评论(0)    收藏  举报