<html>
<head>
<title>look the status change</title>
</head>
<body>
<script type="text/javascript">
var nowtime ;
var year ;
var month ,date,hours,minutes,seconds,all;
function aaa()
{
nowtime = new Date();
year = nowtime.getYear();
month = nowtime.getMonth()+1;
date = nowtime.getDate();
hours = nowtime.getHours();
minutes = nowtime.getMinutes();
seconds = nowtime.getSeconds();
all = year + " "+month +" "+ date +" "+ hours +":"+minutes+":"+seconds;
document.form.text.value=all;
window.setTimeout("aaa();",1000);
}
aaa();
</script>
</body>
</html>
一直报错 不清楚错在哪里 请高手指教

解决方案 »

  1.   

    document.form.text   
    没text这个对象嘛你
      

  2.   

    <html>
    <head>
    <title>look the status change</title>
    </head>
    <body>
    <input type="text" name="text" id="text" />
    <script type="text/javascript">
    var nowtime ;
    var year ;
    var month ,date,hours,minutes,seconds,all;
    function aaa()
    {
    nowtime = new Date();
    year = nowtime.getYear();
    month = nowtime.getMonth()+1;
    date = nowtime.getDate();
    hours = nowtime.getHours();
    minutes = nowtime.getMinutes();
    seconds = nowtime.getSeconds();
    all = year + " "+month +" "+ date +" "+ hours +":"+minutes+":"+seconds;
    document.getElementById("text").value=all;
    window.setTimeout("aaa();",1000);
    }
    aaa();
    </script>
    </body>
    </html>
      

  3.   

    <html>
    <head>
    <title>look the status change</title>
    <script type="text/javascript">
    var nowtime ;
    var year ;
    var month ,date,hours,minutes,seconds,all;
    function aaa()
    {
    nowtime = new Date();
    year = nowtime.getYear();
    month = nowtime.getMonth()+1;
    date = nowtime.getDate();
    hours = nowtime.getHours();
    minutes = nowtime.getMinutes();
    seconds = nowtime.getSeconds();
    all = year + " "+month +" "+ date +" "+ hours +":"+minutes+":"+seconds;
    document.myform.text.value=all;
    //document.getElementById("txt").value = all;
    window.setTimeout("aaa();",1000);
    }</script>
    </head>
    <body onLoad = "aaa()">
    <form name = "myform"><div><input type = "text" id = "txt" name = "text"></div>
    </form>
    </body>
    </html>
      

  4.   

    最好使用nowtime.getFullYear();
    在Firefox等浏览器内getYear返回的是 “当前年份减去1900”的值(即年份基数是1900)
      

  5.   

    <html>
    <head>
    <title>look the status change</title>
    </head>
    <body>
    <script type="text/javascript">
    var nowtime ;
    var year ;
    var month ,date,hours,minutes,seconds,all;
    function aaa()
    {
    nowtime = new Date();
    year = nowtime.getYear();
    month = nowtime.getMonth()+1;
    date = nowtime.getDate();
    hours = nowtime.getHours();
    minutes = nowtime.getMinutes();
    seconds = nowtime.getSeconds();
    all = year + " "+month +" "+ date +" "+ hours +":"+minutes+":"+seconds;
    document.write(all);
    window.setTimeout("aaa();",1000);
    }
    aaa();
    </script>
    </body>
    </html>
    再问一个问题   我写成document.write(all) 为什么 时间就跳两次 就报错了  很不理解   谢谢
    是不是 在时钟这样的问题上是不能用 document.write()的????
      

  6.   

    不能使用,使用标签的innerHTML显示。
    document.write()会默认调用document.open()打开一个新文档。
    你的时钟在页面没有加载完成就执行了,所以第一次document.write()会在本页上显示。当第二次时就会打开一个新的文档,你的脚本也就被覆盖掉了,不能执行了。
      

  7.   

    document.write()输出一次, "window.setTimeout("aaa();",1000);"一秒后又执行一次aaa()方法,故是两次,注意:setTimeout()和setInterval()两者的区别。一般是用innerHTML来显示时间。