父页面和iframe 页面的相互调用 from web
父页面和iframe 页面的相互调用
Code
<html >
<head>
<title>父页面</title>
</head>
<script language=javascript>
function aa()
{
alert(document.frames["tt"].document.body.innerHTML);
}
function bb()
{
alert(tt.document.getElementById("Text1").value); //调用子页面的元素
}
function cc()
{
tt.test(); //调用子页面的函数
}
</script>
<body>
<iframe name=tt id=tt src=child.htm style="width: 372px"></iframe>
<input id="Text1" value="parent" type="text" />
<input id="Button1" onclick="aa()" type="button" value="button" />
<input id="Button2" onclick="bb()" type="button" value="button" />
<input id="Button3" onclick="cc()" type="button" value="button" />
</body>
</html>
--------------------------------------------------------------
<html >
<head>
<title>子页面</title>
</head>
<script language=javascript>
function test()
{
alert("test");
}
function aa()
{
parent.aa(); //调用父页面的函数
alert(parent.document.getElementById("Text1").value); //调用父页面的元素
}
</script>
<body>
<input id="Text1" value="child" type="text" />
<input id="Button1" onclick="aa()" type="button" value="button" />
</body>
</html>