<html> 
<head> 
<title> 小程序</title> 
</head> 
<body> 
<script language="JavaScript">     function  showTime()
    {  
       var thetime= new Date(); // 初始化日期对象
        document.write(thetime.toLocaleString());
        alert(document.documentElement.outerHTML);
        window.setTimeout("alert(showTime);showTime()",1000);
    }
    window.setTimeout("showTime()",1000);
 
</script> 
</body> 
</html>要慎用document.write方法,因为当文档载入完毕之后,调用此方法会清除原文档中的内容,
所以上述错误是由于清除了showTime方法导致,找不到了showTime方法。

解决方案 »

  1.   

    <html> 
    <head> 
    <title> 小程序</title> 
    </head> 
    <body> 
    <script language="JavaScript">     function  showTime()
        {  
           var thetime= new Date(); // 初始化日期对象
            document.getElementById("timeArea").innerText = thetime.toLocaleString();
            window.setTimeout("showTime()",1000);
        }
        window.setTimeout("showTime()",1000);
     
    </script> 
    <div id="timeArea"></div>
    </body> 
    </html>建议采用修改页面某个dom节点的innerText方式实现
      

  2.   

    <html> 
    <head> 
    <title> 小程序</title> 
    </head> 
    <body> 
      <div id=divtime></div>
    <script language="JavaScript"> 
       window.onload=showTime();
        function  showTime()
        {  
           var thetime= new Date(); // 初始化日期对象        divtime.innerHTML=thetime.toLocaleString();
            window.setTimeout("showTime()",1000);
        }
        
     
    </script> 
     
    </body> 
    </html>