这里面有没很熟悉javacript的,请教一个问题:
我在用
<frameset>
<frame src="aa.html" name="aa"/>
<frame src="bb.html" name="bb"/>
</frameset>
这个html元素,我在BB页面用javascript控制AA页面,语句为:self.parent.aa.style.display =''none";结果IE报错为:self.parent.aa为空或不是对象。真不解啊,我在网上查了很多网友也是这样做的,为什么我做的就不行,请高手赐教!

解决方案 »

  1.   

    你把JS放在哪了要注意JS的加载顺序
      

  2.   

    把<frameset>
    <frame src="aa.html" name="aa"/>
    <frame src="bb.html" name="bb"/>
    </frameset>
    改成
    <frameset>
    <frame src="aa.html" id="aa"/>
    <frame src="bb.html" id="bb"/>
    </frameset>
      

  3.   

    我把JS放在BB的<head></head>中。
      

  4.   

    我把JS放在BB的<head></head>中。
      

  5.   

    我是把JS放在BB页面的<head></head>中,由button的onclick()事件触发。 
      

  6.   

    LZ的问题是self.parent.aa.style.display中的aa取的是id而不是name
      

  7.   

    name和id都设了,都是相同的aa,bb
      

  8.   

    LZ测试过以下的代码没?<frameset>
    <frame src="aa.html" id="aa"/>
    <frame src="bb.html" id="bb"/>
    </frameset>我本地测试是没问题的
      

  9.   

    self.parent.frames['aa'].style.display='none'试试这个呢?。。
      

  10.   

    这样看看,下面例子...主页面:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><frameset rows="116,*" cols="*" framespacing="0" frameborder="NO" border="1">
      <frame src="ajax007_01.htm" name="topFrame" scrolling="NO" noresize>
      <frame src="ajax007_02.htm" name="mainFrame">
    </frameset>
    <noframes><body>
    </body></noframes>
    </html>
    子页面1:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Ajax007_01.htm</title>
    <style type="text/css">
    body{font-size:12px; font-family:arial; color:#333333; font-weight:bold;background-color: #004080;}
    td{font-size:12px; font-family:arial; color:#333333; font-weight:bold}
    </style>
    </head>
    <script type="text/javascript" language="javascript">
    function showx(){
    alert("This function is defined in top Frame: topFrame window...");
    }</script>
    <body>
    <p><font color="#FFFFFF">TOP Frame window</font></p>
    <font color="#FFFFFF">
    Frame name: topFrame<br>
    Frame src: Ajax007_01.htm
    </font>
    </body>
    </html>
    子页面2:onClick="javascript:parent.topFrame.showx();"关键地方<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Ajax007_02.htm</title>
    </head>
    <style type="text/css">
    body{font-size:12px; font-family:arial; color:#333333; font-weight:bold;}
    td{font-size:12px; font-family:arial; color:#333333; font-weight:bold}
    </style>
    <body>
    <p>Main Frame window</p>
    <p>引用上一个Frame的函数</p>
    <br>
    <input id="btn01" name="btn01" value="click" type="button" onClick="javascript:parent.topFrame.showx();">
    <p>调用: onClick=&quot;javascript:parent.topFrame.showx();&quot;</p>
    <p>&nbsp;</p>
    Frame name: mainFrame<br>
    Frame src: Ajax007_02.htm
    </body>
    </html>
    LZ 结帖,分分了
      

  11.   

    setTimeout(function(){self.parent.frames['aa'].style.display='none';},500);
    这样试试
      

  12.   

    现在试了二个种方法:
    1、self.parent.aa.style.display='none';
    2、self.parent.frames['aa'].style.display='none';都报同一个错:self.parent.aa.style为空或不是对象,self.parent.frames['aa'].style为空或不是对象。
    self.parent.aa没有报对象为空了。
      

  13.   

    To shenzhenNBA,我看了你的回复,但不是我想要的效果,我要效果是:在B页面中的一个按钮,当点击它时,A页面隐藏,再点击时显示A页面,而A、B页面之间的大小是可以像二个窗体间互相拖动调整大小窗口。
      

  14.   


    我那里是现实在b页面如果控制a 页面的中函数,你稍加修改就可以了,“A页面隐藏”?是页面中的某个元素隐藏吧?
      

  15.   

    修改如下:要实现拖动功能你再自己实现,里面不断改变值,并调用修改窗口大小的函数即可;主页面:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><frameset id="frames" name="frames" rows="30%,69%" cols="*" framespacing="2" frameborder="2" border="2">
      <frame src="ajax007_01.htm" name="topFrame" scrolling="NO" noresize>
      <frame src="ajax007_02.htm" name="mainFrame">
    </frameset>
    <noframes><body>
    </body></noframes>
    </html>
    子页面1:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Ajax007_01.htm</title>
    <style type="text/css">
    body{font-size:12px; font-family:arial; color:#333333; font-weight:bold;background-color: #004080;}
    td{font-size:12px; font-family:arial; color:#333333; font-weight:bold}
    </style>
    </head>
    <script type="text/javascript" language="javascript">
    function $(id){
    return 'string'==typeof(id) ? document.getElementById(id) : id;
    }function showHide(id,showFlag){
    var f=showFlag.toLowerCase();
    var o=$(id);
    if(f=='hide')
    o.style.display='none';
    else
    o.style.display='block';
    }</script>
    <body>
    <div id="div01">
    <p><font color="#FFFFFF">TOP Frame window</font></p>
    <font color="#FFFFFF">
    Frame name: topFrame<br>
    Frame src: Ajax007_01.htm
    </font>
    </div>
    </body>
    </html>子页面2:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Ajax007_02.htm</title>
    </head>
    <style type="text/css">
    body{font-size:12px; font-family:arial; color:#333333; font-weight:bold;}
    td{font-size:12px; font-family:arial; color:#333333; font-weight:bold}
    </style>
    <script type="text/javascript" language="javascript">
    function $(id){
    return 'string'==typeof(id) ? document.getElementById(id) : id;
    }function changeWin(){
    var h=0;
    try{
    h=parseInt($('wh').value)
    }catch(e){
    h=20;
    }
    if(h>=100) h=90; //must be save some space for B page
    parent.document.getElementById('frames').rows=''+h+'%,*'; //change the heiht of top frame
    }
    </script>
    <body>
    <p>Main Frame window</p>
    <p>引用上一个Frame的函数</p>
    <br><input id="btn01" name="btn01" value="隐藏上窗口内容" type="button" onClick="javascript:parent.topFrame.showHide('div01','hide');">
    <input id="btn01" name="btn01" value="显示上窗口内容" type="button" onClick="javascript:parent.topFrame.showHide('div01','show');">
    &nbsp;&nbsp;&nbsp;&nbsp;
    输入窗口高度大小值:<input id="wh" name="wh" value="20" type="text">% 
    <input id="btn01" name="btn01" value="窗口大小更改" type="button" onClick="javascript:changeWin();">
    <p>调用: onClick=&quot;javascript:parent.topFrame.showx();&quot;</p>
    <p>&nbsp;</p>
    Frame name: mainFrame<br>
    Frame src: Ajax007_02.htm
    </body>
    </html>分分,赶紧结帖了
      

  16.   


    <frameset id="mainframe">
    <frame src="aa.html" name="aa"/>
    <frame src="bb.html" name="bb"/>
    </frameset>parent.document.getElementById("mainframe").cols = "0,*";