在你的函数下面加入setInterval("myclock()",1000);或者在函数内部最下面加入setTimeout("myclock()",1000);
然后在函数下面加入myclock();

解决方案 »

  1.   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head>
    <body>
    <INPUT name=aa size="49">
    <script language="JavaScript">
    <!--
    window.setInterval("myclock()",1000);function myclock()

    var thetime=new Date();
    var theyear=thetime.getFullYear();
    var themonth=thetime.getMonth();
    var theday=thetime.getDate();
    var theweekday=thetime.getDay();
    var thehour=thetime.getHours();
    var theminute=thetime.getMinutes();
    var thesecond=thetime.getSeconds();
    var theafternoon="A.M";
    var abc= new Array(7)
    abc[0]="Sunday";
    abc[1]="monday";
    abc[2]="tuesday";
    abc[3]="wednesday";
    abc[4]="thursday";
    abc[5]="friday";
    abc[6]="saturday";
          if(thehour>12)
              {thehour-=12;
               theafternoon="P.M";}
        themonth++;
       aa.value=abc[theweekday]+"/"+theyear+"/"+themonth+"/"+theday+"  "+thehour+"/"+theminute+"/"+thesecond+"  Whether it is"+theafternoon;
    }
       
    window.setInterval("myclock()",1000);
    //-->
    </script>
    </body>
    </html>
      

  2.   

    谢谢,楼上的兄弟,可是我还是有个问题,就是abc[theweekday]+"/"+theyear+"/"+themonth+"/"+theday+"  "+thehour+"/"+theminute+"/"+thesecond+"  Whether it is"+theafternoon;
    为什么用document.write写在页面里不可以,而像你那样aa.value就可以,还有,这个aa.value是什么啊?
      

  3.   

    对应于 <INPUT name=aa size="49">
    此外可以用这样的方法,在页面中定义<p id="aa"></p>

    aa.value=abc[theweekday]+"/"+theyear+"/"+themonth+"/"+theday+"  "+thehour+"/"+theminute+"/"+thesecond+"  Whether it is"+theafternoon;
    改为
    value=abc[theweekday]+"/"+theyear+"/"+themonth+"/"+theday+"  "+thehour+"/"+theminute+"/"+thesecond+"  Whether it is"+theafternoon;
    document.all("aa").innerText=value;又你定义的显示不符合规范,我是这样定义的
    value=abc[theweekday]
             +"  "+theyear+"/"+
              ((themonth>9)?themonth:("0"+themonth))+"/"+
              ((theday>9)?theday:("0"+theday))+"  "+
              ((thehour>9)?thehour:("0"+thehour))+":"+
              ((theminute>9)?theminute:("0"+theminute))+":"+
              ((thesecond>9)?thesecond:("0"+thesecond))+"  Whether it is"+theafternoon;
      

  4.   

    哦,我有点明白了,那是不是用document.write的输出是不可以的呢?