如何用JavaScript在页面上显示一个时间钟表

<html>
<head>
<script type="text/javascript">
function myTime(){
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();

m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h+":"+m+":"+s;
t=setTimeout('startTime()',500)
}

//add a '0' in front of numbers<10
function checkTime(i);
{
if(i<10)
{i="0" + 1}
return i;
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
</body>
</html>

posted @ 2015-10-12 11:06  wjwdive  阅读(867)  评论(0编辑  收藏  举报