在jsp页面中,frame之间以及子页面和父页面间参数是如何传递

本文介绍了一个HTML示例,展示了如何在父页面与子页面之间互相访问特定ID的元素。通过JavaScript函数`getChildEl()`和`getParentEl()`实现从父页面访问子页面元素及反之的功能。并提到了不同浏览器如IE6与Firefox之间的兼容性差异。
看示例代码
父页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>父页面</title>
<script type="text/javascript">
function getChildEl(){
alert(document.frames("inner").document.getElementById("text1.inner").value);
}

</script>
</head>

<body>
<input type="text" id="text1.outter" value="outter text"/>
<input type="button" value="访问子页面" onclick="getChildEl()" />
<br/>
<iframe id="inner" name="inner" src="child.html"></iframe>
</body>

</html>


子页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>子页面</title>
<script type="text/javascript">
function getParentEl(){
alert(parent.document.getElementById("text1.outter").value);
}
</script>
</head>


<body>
<input type="text" id="text1.inner" value="inner text"/>
<input type="button" value="访问父页面" onclick="getParentEl()" />
</body>
</html>


经过测试:

//在子页面访问子页面时(子页面通过父页面访问其他的子页面),以下三种在IE6下均通过验证,但是在firefox中,第一种方式没有通过验证,其他均没问题。其中frame3为frame的name属性值
parent.document.frames("frame3").document.getElementById("test3").value=data;
parent.frames["frame3"].document.getElementById("test3").value=data;
parent.frame3.document.getElementById("test3").value=data;



[size=large]相关文章:
http://longhuang.iteye.com/blog/693827[/size]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值