zoukankan      html  css  js  c++  java
  • iframe 父页面与子页面之间的方法的相互调用

     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     <title>Parent Page</title>
     5         <script language="javascript" type="text/javascript">
     6             function parenttest() {
     7                 alert("这是父页面的方法!");
     8             }
     9             function btnClick() {
    10                 document.getElementById("childframe").contentWindow.childtest();
    11             }
    12     </script>
    13 </head>
    14 <body>
    15    <div style="margin:auto;">
    16        <h1>This is the Parent Page.</h1>
    17        <input type="button" value="调用子页面的方法"  onclick="btnClick()"/> 
    18     </div>
    19     <div style="margin:auto;">
    20        <iframe style="300px; height:300px;" id="childframe" src="ChildPage.html"></iframe>
    21     </div>
    22 </body>
    23 </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     <title>Child Page</title>
     5     <script language="javascript" type="text/javascript">
     6       function childtest() {
     7           alert("这是子页面的方法!");
     8       }
     9       function btnClick() {
    10           window.parent.parenttest();
    11       }
    12     </script>
    13 </head>
    14 <body>
    15    <div style="margin:auto;">
    16        <h1>This is the Child Page.</h1>
    17        <input type="button" value="调用父页面的方法" onclick="btnClick()"/> 
    18     </div>
    19 </body>
    20 </html>
  • 相关阅读:
    HDU 1950 Bridging signals
    HDU 1025 (LIS+二分) Constructing Roads In JGShining's Kingdom
    HDU 1160 FatMouse's Speed
    HDU 1257 最少拦截系统
    HDU 1574 RP问题
    解同余式ax ≡ c(mod m)
    拓展欧几里得算法及代码实现
    百练 1088 滑雪
    [再做01背包] POJ 3624 Charm Bracelet
    百练 2755 神奇的口袋
  • 原文地址:https://www.cnblogs.com/taojietx/p/5287203.html
Copyright © 2011-2022 走看看