日期:2014-05-16  浏览次数:20405 次

在jsp页面中,frame之间以及子页面和父页面间参数是如何传递
看示例代码
父页面:
<!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;



相关文章:
http://longhuang.iteye.com/blog/693827