你这个调用法应该没什么问题,但好的编程习惯还是把函数放到head里吧

解决方案 »

  1.   

    可是我在写网页写到一个地方时,需要用时间在<body>里面
      

  2.   

    document.write(...)
    ->
    document.body.innerHTML=(...)
      

  3.   

    <html>
    <head>
    <style>
    input{border:0px;border-bottom:1px red solid;text-align:center;}
    </style></head>
    <body>
    <div id=nt></div>
    <script>function date(){
    var now=new Date();
    var hour=now.getHours();
    var minu=now.getMinutes();
    var second=now.getSeconds();
    var amp="AM";
    if(hour<=23&&hour>=12){
    amp="PM";
    }
    if(minu<10){
    minu="0"+minu;
    }
    if(second<10){
    second="0"+second;
    }
    nt.innerHTML="现在时间是:"+now.getYear()+"年"+(now.getMonth()+1)+"月"+now.getDate ()+"日"+" "+now.getHours()+":"+minu+":"+second+"秒"+" "+amp;
    setTimeout("date()",1000);
    }document.onload=date()
    </script>
    </body>
    </html>