请教一个JAVASCRIPT问题

finered 2012-02-07 09:47:02
这里面有没很熟悉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为空或不是对象。

真不解啊,我在网上查了很多网友也是这样做的,为什么我做的就不行,请高手赐教!
...全文
187 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenzhenNBA 2012-02-07
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 finered 的回复:]

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

我那里是现实在b页面如果控制a 页面的中函数,你稍加修改就可以了,“A页面隐藏”?是页面中的某个元素隐藏吧?
finered 2012-02-07
  • 打赏
  • 举报
回复
To shenzhenNBA,我看了你的回复,但不是我想要的效果,我要效果是:在B页面中的一个按钮,当点击它时,A页面隐藏,再点击时显示A页面,而A、B页面之间的大小是可以像二个窗体间互相拖动调整大小窗口。
finered 2012-02-07
  • 打赏
  • 举报
回复
现在试了二个种方法:
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没有报对象为空了。
hch126163 2012-02-07
  • 打赏
  • 举报
回复
setTimeout(function(){self.parent.frames['aa'].style.display='none';},500);
这样试试
shenzhenNBA 2012-02-07
  • 打赏
  • 举报
回复
这样看看,下面例子...

主页面:

<!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="javascript:parent.topFrame.showx();"</p>
<p> </p>
Frame name: mainFrame<br>
Frame src: Ajax007_02.htm
</body>
</html>


LZ 结帖,分分了。。。
三石-gary 2012-02-07
  • 打赏
  • 举报
回复
self.parent.frames['aa'].style.display='none'试试这个呢?。。
  • 打赏
  • 举报
回复
LZ测试过以下的代码没?
<frameset>
<frame src="aa.html" id="aa"/>
<frame src="bb.html" id="bb"/>
</frameset>


我本地测试是没问题的
finered 2012-02-07
  • 打赏
  • 举报
回复
name和id都设了,都是相同的aa,bb
  • 打赏
  • 举报
回复
LZ的问题是self.parent.aa.style.display中的aa取的是id而不是name
finered 2012-02-07
  • 打赏
  • 举报
回复
我是把JS放在BB页面的<head></head>中,由button的onclick()事件触发。
finered 2012-02-07
  • 打赏
  • 举报
回复
我把JS放在BB的<head></head>中。
finered 2012-02-07
  • 打赏
  • 举报
回复
我把JS放在BB的<head></head>中。
  • 打赏
  • 举报
回复
把<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>
三石-gary 2012-02-07
  • 打赏
  • 举报
回复
你把JS放在哪了。。。要注意JS的加载顺序。。。
未知数 2012-02-07
  • 打赏
  • 举报
回复
直接写在全局的js,会在页面加载完成前执行,你把这句写到一个事件函数中执行就可以了
三石-gary 2012-02-07
  • 打赏
  • 举报
回复

<frameset id="mainframe">
<frame src="aa.html" name="aa"/>
<frame src="bb.html" name="bb"/>
</frameset>

parent.document.getElementById("mainframe").cols = "0,*";

shenzhenNBA 2012-02-07
  • 打赏
  • 举报
回复
修改如下:要实现拖动功能你再自己实现,里面不断改变值,并调用修改窗口大小的函数即可;

主页面:

<!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');">
    
输入窗口高度大小值:<input id="wh" name="wh" value="20" type="text">%
<input id="btn01" name="btn01" value="窗口大小更改" type="button" onClick="javascript:changeWin();">
<p>调用: onClick="javascript:parent.topFrame.showx();"</p>
<p> </p>
Frame name: mainFrame<br>
Frame src: Ajax007_02.htm
</body>
</html>

分分,赶紧结帖了。。。


87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧