javascript中setTimeout()的用法

我想制作一个秒表.但是好像setTimeout(0不能支持1000mm以下的时间呀.还是我的程序有问题.帮我看看是怎么了.谢谢.

<title>秒表</title>

<script language="javascript">

function showing()
{
// showFast();
setInterval("showTime()",1000);
}
function showTime() //每一秒刷新一次
{
mytime=new Date(); //创造一个时间对象比获得他的时间元素
year=mytime.getYear();
date=mytime.getDate();
month=mytime.getMonth();
day=mytime.getDay();
hours=mytime.getHours();
minutes=mytime.getMinutes();
seconds=mytime.getSeconds();
temp="上午好";
Astr=new String("");
formatTime(hours.minutes,seconds);
Astr+=("<font size='+1' color='red'>"+year+"年"+month+"月"+date+"日"+"星期"+(day+1)+"</font>");
document.getElementById("lay3").innerHTML=Astr;
Bstr="<font size='+1' color='red'>"+temp+hours+":"+minutes+":"+seconds+"</font>";
document.getElementById("lay1").innerHTML=Bstr;
for(s=0;s<100;++s) //从00到99循环
{
setTimeout("",10);
document.getElementById("lay2").innerText=s;
// if(s<10) s="0"+s;
// setTimeout("showI(s)",10);
// if(s=99)s=0;
}

}
function showI(s)
{
document.getElementById("lay2").innerText=s;
}

function formatTime()
{
if(hours!=0&&hours<=7) //决定问候语
temp="早上好";
else if(hours>7&&hours<11)
temp="上午好";
else if(hours>=11&&hours<13)
temp="中午好";
else if(hours>=13&&hours<=18)
temp="下午好";
else if(hours>18&&hours<24)
temp="晚上好";
if(hours<=9)hours="0"+hours; //格式化时间使之以两位数的格式显示
if(minutes<=9)minutes="0"+minutes;
if(seconds<=9)seconds="0"+seconds;
}

/*function showFast()
{
for(s=0;s<100;s++)
{
if(s<10) s="0"+s;
setTimeout("showI(s)",10);
// if(s=99)s=0;
}

} */

</script>
<style type="text/css">
<!--
#lay3 {
position:absolute;
left:367px;
top:134px;
width:246px;
height:42px;

}
#Lay1 {
position:absolute;
left:368px;
top:178px;
width:182px;
height:38px;

}
#lay2 {
position:absolute;
left:552px;
top:178px;
width:63px;
height:39px;

}
-->
</style>
</head >
<body onload="showing()">
<span id="lay3"></span>
<span id="Lay1"></span>
<span id="lay2"></span>
</body>
</html>

可怜的孩子...辛苦你了, 写了这么一大篇, 为了实现一个数字时钟的功能...这让我想起了我小时候...

你的错误就在于:
<span id="Lay1"></span>及
document.getElementById("lay1")
发现没有啊, 粗心的孩子, lay1两处大小写不一致呵...
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答