最近一直看javaScript里面有一个练习,还是不太清楚,他说   用超时来写一个实时的时钟程序,用到location.reload这个方法,但是我是写了,就是出不来,请各位帮帮忙啊

解决方案 »

  1.   

    <html><head><title>THE DATE AND TIMES TEST</title>
    <script language="javascript" type="text/javascript">
    ID=window.setTimeout("update();",2000);
    function update()
    {
     now=new Date();
     hours=now.getHours();
     minu=now.getminutes();
     secs=now.getSeconds();
     
     ID=window.setTimeout("update();",2000);
    }
    document.write(hours+":"+minu+":"+secs);
    </script>
    </head>
    <body>
    <h1>Current times and Dates</h1>
    <input type="button" value="reload" onClick="update();">
    </body>
    </html>
      

  2.   

    <script type="text/javascript">
    <!--
        function  refreshCalendarClock(){  
            document.getElementById("showclock").innerHTML=thisYear()+Year_Month()+Date_of_Today()+Day_of_Today()+CurentTime();
            }
        function  thisYear(){  
            var  now  =  new  Date();
            var  yy  =  now.getFullYear()+"年";  
            return(yy  );  }
        function  Year_Month(){  
            var  now  =  new  Date();
            now.toTimeString();  
            var  mm  =  (now.getMonth()+1)+"月";  
            return(mm  );  }
        function  Date_of_Today(){  
            var  now  =  new  Date();
            return(now.getDate()+"日"  );  }
        function Day_of_Today(){
            var now=new Date();
            var week=new Array(" 星期日 "," 星期一 "," 星期二 "," 星期三 "," 星期四 "," 星期五 "," 星期六 ");
            return(week[now.getDay()]);}    
        function  CurentTime(){  
            var  now  =  new  Date();  
            var  hh  =  now.getHours();  
            var  mm  =  now.getMinutes();  
            var  ss  =  now.getTime()  %  60000;  
            ss  =  (ss  -  (ss  %  1000))  /  1000;  
            var  clock  =  hh+':';  
            if  (mm  <  10)  clock  +=  '0';  
            clock  +=  mm+':';  
            if  (ss  <  10)  clock  +=  '0';  
            clock  +=  ss;  
            return(clock);  }  
        setInterval('refreshCalendarClock()',1000);
    //-->
    </script>
    显示用<div id="showclock"></div>或span