<html>
  <head>
function f(){
  
  document.body.innerText=""+index;
  index++;
window.setTimeout("f()",1000);
}
</script>
  </head>
    <div id="grant"></div>
  <body onload="f()">
  
  </body>
</html>对象 grant 的创建 再 执行过程之后。   你把<div id="grant"></div> 放前边就OK了

解决方案 »

  1.   

    document.grant.innerText//没这种写法
    ==>
    document.getElementById("grant").innerText
      

  2.   

    <html>
      <head>
    <script type="text/javascript">
    function f(){
      
      document.getElementById("grant").innerText=index;
      index++;
    window.setTimeout("f()",1000);
    }
    </script>
      </head>
      
      <body onload="f()">
        <div id="grant"></div>
      </body>
    </html>
      

  3.   

    document.getElementById("grant")orwindow.grant
      

  4.   

    好像对DIV,不能用document+DIVID,要不就直接用grant.innerText,或document.getElementByID("grand").innerText
      

  5.   

    谢谢楼上两位的指点,成功了,我是javascript初学者
    有个问题想请教一下,调用grant.innerText=""+index也没有错,grant不是document一部分吗
      

  6.   

    我前面不是写上去了吗id是在window下的