请帮我看看我的定时器哪里出错了,感激不尽
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>定时器</title> <script type="text/javascript"> var attime,h,m,s; function clock(){ var time=new Date(); h=time.getHours(); m=time.getMinutes(); s=seconds.getSeconds(); var week=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]; attime= h+":"+m+":"+s+":"+week[time.getDay()] ; document.getElementById("clock").value = attime; } var int=setInterval(clock,100); </script> </head> <body> <form> <input type="text" id="clock" size="50" /> </form> </body> </html>
还有就是我看了下这位同学的答案,为什么他的setInterval没有写间隔时间也可以运行,不是说必须要写的吗?
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>定时器</title> <script type="text/javascript"> var attime,hh,mm,ss,ww,xx; function clock(){ var time=new Date(); hh=time.getHours(); mm=time.getMinutes(); ss=time.getSeconds(); if(mm<10){hh="0"+mm}; if(hh<10){hh="0"+hh}; if(ss<10){ss="0"+ss}; var week=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"] ww=time.getDay() xx=week[ww] attime= hh+":"+mm+":"+ss+xx; document.getElementById("clock").value = attime; } var int=setInterval(clock) </script> </head> <body> <form> <input type="text" id="clock" size="50" /> </form> </body> </html>