在frame的主窗口和子窗口之间的传值和方法调用

本文详细介绍了在Frame结构中如何在不同子页面之间调用变量和方法,包括使用parent对象的不同方法如document.frames, parent.页面名 和 parent.frames[页面名]。通过实例展示了在主页面和子页面间的相互调用过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值