父页面
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
5 <title>iframe父子页面取值</title>
6 <script type="text/javascript">
7 function say() {
8 alert("parent");
9 }
10 function callChild() {
11 //document.frames["myFrame"].window.say();//只适用于ie浏览器
12 myFrame.window.say();
13 myFrame.window.document.getElementById("button").value = "我变了";
14 }
15 </script>
16 </head>
17 <body>
18 <input type=button value="调用child.html中的函数say()" onclick="callChild()">
19 <iframe name="myFrame" src="b_2.html"></iframe>
20 </body>
21 </html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
5 <title>iframe父子页面取值</title>
6 <script type="text/javascript">
7 function say() {
8 alert("parent");
9 }
10 function callChild() {
11 //document.frames["myFrame"].window.say();//只适用于ie浏览器
12 myFrame.window.say();
13 myFrame.window.document.getElementById("button").value = "我变了";
14 }
15 </script>
16 </head>
17 <body>
18 <input type=button value="调用child.html中的函数say()" onclick="callChild()">
19 <iframe name="myFrame" src="b_2.html"></iframe>
20 </body>
21 </html>
子页面
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
5 <title>iframe父子页面取值</title>
6 <script type="text/javascript">
7 function say() {
8 alert("child");
9 }
10 function callParent() {
11 parent.say();
12 parent.window.document.getElementsByName("myFrame")[0].style.height = "100px";
13 }
14 </script>
15 </head>
16 <body>
17 <input id="button" type=button value="调用parent.html中的say()函数" onclick="callParent()">
18 </body>
19 </html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
5 <title>iframe父子页面取值</title>
6 <script type="text/javascript">
7 function say() {
8 alert("child");
9 }
10 function callParent() {
11 parent.say();
12 parent.window.document.getElementsByName("myFrame")[0].style.height = "100px";
13 }
14 </script>
15 </head>
16 <body>
17 <input id="button" type=button value="调用parent.html中的say()函数" onclick="callParent()">
18 </body>
19 </html>