index.html 总体框架显示:
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function ppp(){
alert(window.frames ["top"].aaa());
}
</script>
</head>
<frameset rows="18%,*" framespacing="0">
<frame src="top.html" name= "top" scrolling="No" noresize="noresize" frameborder="no"/>
<frameset cols="70%,*">
<frame src="left.html" name="left" scrolling="No" noresize="noresize" title="leftFrame" frameborder="no"/>
<frame src="right.html" name="right" scrolling="auto" noresize="noresize" title="message" frameborder="no"/>
</frameset>
</frameset>
<noframes></noframes>
<body>
</body>
</html>
top.html 上部界面显示:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>top</title>
<script type="text/javascript">
function aaa(){
var str="hello";
alert(str);
}
</script>
</head>
<body bgcolor="#CCCCFF">
top
<div id="test">aaaaaaaaaaaaa</div>
</body>
</html>
left.html 左侧界面显示:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>left</title>
</head>
<script type="text/javascript">
function test1(){
parent.ppp();
}
</script>
<body bgcolor="#0099FF">
left
</body>
<input type="button" οnclick="test1()" value="调用top" />
</html>
right.html 右侧界面显示:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>right</title>
</head>
<body bgcolor="#99CC99">
right
</body>
</html>
目的是通过left界面调用到top的函数,方法是先调用父窗体index的函数ppp(),再通过ppp来调用top的ttt()函数,试了各种办法都不行,最后我发现left可以调用right的函数,却不可以调用top的函数,我开始认为是frameset的原因,第二个frameset将top和left分开了,但我试着将right和top调换位置,left竟然还不能调用top的函数,我逐渐对比right.html和top.html的内容,最后试着将top换了个名字,神奇般的可以了!我想top应该是一个保留关键字吧,我将top改为tt即可运行成功。
ps:(其实,left调用top还可以这么写:parent.window.frames["tt"].aaa(),即将left调用index和index调用top合二为一了。)