<html>
<head>
<title>clock</title>
<script language="javascript">
var timerID = null; //Here
var timerRunning = false;
function stopClock() {
if (timerRunning)
{
clearTimerout(timerID);
timerRunning = false;
document.clock.face.value = "";
}
}
function showTimer(){
//timerID =setTimeout("showTimer()",1000); //Here
var now =new Date();
var year= now.getYear();
var month = now.getMonth() + 1 ;
var date = now.getDate();
var hours = now.getHours();
var mins = now.getMinutes();
var secs = now.getSeconds();
var timerVar = "";
timerVar += year +"年"
timerVar +=((month <10)?"0" + month : month) + "月";
timerVar += date + "日"
timerVar += ((hours<12) ? hours:hours - 12) + "点";
timerVar +=((mins < 10)?":0":":") + mins + "分";
timerVar +=((secs < 10)?":0":":") + secs + "秒";
document.clock.face.value = timerVar;
window.status= clock.face.value;
timerID = setTimeout("showTimer()",1000);//Here
timerRunning = true;
}
function startClock(){
showTimer();
}
</script>
</head>
<body onLoad="startClock()">
<p align="center"><big><span style="background-color:rgb(45,45,45)">
<font face="宋体">时钟</font>
</span></big></p>
<table border="0" cellspacing="0" cellpadding="0">
<tr><td width="100%">
<form NAME="clock">
        <input Type="rext" NAME="face" size="30" style="background-color:rgb(100,100,60)">
</form>
</td>
</tr>
</table>
</body>
</html>

解决方案 »

  1.   

    TO:ptma(守望者)是变量的timerID的大小写问题吗?这个我已经改啦但还是不行还是因为变量跟关键字方面的问题?setTimeout("子程序名",时间)这个语句也有错吗?
      

  2.   

    第33行
    timerID = setTimeout("showTime()",1000);
    应为
    timerID = setTimeout("showTimer()",1000);
    其实这一行去掉就可以
    与第16行是重的
      

  3.   

    TO:mmmaaaggg(忘我)我在那加上那一行是因为我想让它变成动态时钟啊。如果没有那一行他只是取第一次的时间不会计时的。不能在那里加的吗?那我想把它做成动态的应该怎么做呢?
      

  4.   

    守望的代码没问题啊.
    他已在修改的那一行加了注释!
    timerID = setTimeout("showTimer()",1000);//Here"showTime()"
    ----->>>>>
    "showTimer()"