为了账号安全,请及时绑定邮箱和手机立即绑定

为什么setTimeout(0不能支持1000mm以下的时间呀?还是我的程序有问题?帮我看看是怎么了

为什么setTimeout(0不能支持1000mm以下的时间呀?还是我的程序有问题?帮我看看是怎么了

慕森卡 2022-11-20 22:18:28
<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>
查看完整描述

1 回答

?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

可怜的孩子...辛苦你了, 写了这么一大篇, 为了实现一个数字时钟的功能...这让我想起了我小时候...
你的错误就在于:
<span id="Lay1"></span>及
document.getElementById("lay1")
发现没有啊, 粗心的孩子, lay1两处大小写不一致呵...

查看完整回答
反对 回复 2022-11-24
  • 1 回答
  • 0 关注
  • 82 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号