这里面有没很熟悉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为空或不是对象。真不解啊,我在网上查了很多网友也是这样做的,为什么我做的就不行,请高手赐教!
我在用
<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为空或不是对象。真不解啊,我在网上查了很多网友也是这样做的,为什么我做的就不行,请高手赐教!
<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>
<frame src="aa.html" id="aa"/>
<frame src="bb.html" id="bb"/>
</frameset>我本地测试是没问题的
<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 结帖,分分了
这样试试
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没有报对象为空了。
我那里是现实在b页面如果控制a 页面的中函数,你稍加修改就可以了,“A页面隐藏”?是页面中的某个元素隐藏吧?
<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>分分,赶紧结帖了
<frameset id="mainframe">
<frame src="aa.html" name="aa"/>
<frame src="bb.html" name="bb"/>
</frameset>parent.document.getElementById("mainframe").cols = "0,*";