为什么找不到对象
我在一个帧中这样写
     var mainfra=window.parent.document.all.mainframe;
就没有问题?

解决方案 »

  1.   

    mainfra 找不到
    topfra 也找不到
      

  2.   

    这个是很典型的错误,你把<script>...</script>的内容放到最后就可以了,因为你的FRAMESET还没有出来,你的script语句就使用了它。
      

  3.   

    to lignninglei:
      我把它放在后面,他就根本不执行???
      

  4.   

    试试看这个:
    <script>
    function window.onload()
      {var mainfra=mainframe;
       var topfra=topframe;
       if(topfra.location=="main_top_up.jsp")
         {alert("25")
          mainfra.rows="25,*,20";
         }
       else
         {alert("110")
          mainfra.rows="110,*,20";
          topfra.location="main_top.jsp";
         }
      }
    </script>
      

  5.   

    楼上的没错,就是这个了。是你自己没有定义mainfra和topfra,我实在是不知道你这两个变量是怎么引用的。
      

  6.   

    把<script> 改成
    <script defer> 也可以的
    我不知道defer 是什么意思。
      

  7.   

    window.onload = function() {
      var mainfra=window.document.all.mainframe;
      var topfra=window.document.all.topframe;
      if(mainfra){
          if(topfra){
    if(topfra.src=="main_top_up.jsp"){
      alert("25")
              mainfra.rows="25,*,20";
    }else{
      alert("110")
      mainfra.rows="110,*,20";
      topfra.src="main_top.jsp";
            }
          }
        }
    }改成这样啦!
    你要访问document一下的对象必须有事件触发,不然是找不到对象的。
      

  8.   

    把<script> 改成
    <script defer> 就可以了defer [CI] 
    When set, this boolean attribute provides a hint to the user agent that the script is not going to generate any document content (e.g., no "document.write" in javascript) and thus, the user agent can continue parsing and rendering. 
    程序下载完后再进行解析和执行