在frame中的子页面调用其他子页面的变量和方法:
1. parent.document.frames("子页面name").子页面方法();
2. parent.子页面name.子页面方法();
3. parent.frames["子页面name"].子页面方法();
例如:
1. parent.document.frames("top").tops();
2. parent.top.tops();
3. parent.frames["top"].tops();
在frame中主页面调用其他子页面的变量和方法:
1.子页面name.子页面方法()
2.子页面name.子页面变量
如下例子:
1.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("I'm parent");
}
</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>
2.top.htlm
<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 tops(){
alert("I'm top");
}
</script>
</head>
<body bgcolor="#CCCCFF">
top
</body>
</html>
3.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.document.frames("top").tops();
//parent.top.tops();
//parent.frames["top"].tops();
}
</script>
<body bgcolor="#0099FF">
left
</body>
<input type="button" onclick="test1()" value="调用top" />
</html>
4.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>