javascript中setTimeout()的用法
我想制作一个秒表.但是好像setTimeout(0不能支持1000mm以下的时间呀.还是我的程序有问题.帮我看看是怎么了.谢谢.<title>秒表</title><scr...
我想制作一个秒表.但是好像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> 展开
<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> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询