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

    父页面:

    <!DOCTYPE html>
    <html>
    <head>
        <title>parents</title>
        <meta charset="UTF-8">
    </head>
    <body>
    <div id="default">div内容</div>
    <iframe src="child.html" id="child"></iframe>
     <script language="javascript" type="text/javascript"> 
      function sayhello() {
        alert(
    'Hello World!');
      }
      var value = 'value';
      child.contentWindow.test();
    </script> </body> </html>

    子页面:

    <!DOCTYPE html>
    <html>
    <head>
        <title>child</title>
        <meta charset="UTF-8">
        <script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
        <script language="javascript" type="text/javascript">
            $(function() {
                //在iframe子页面中查找父页面元素
                alert($('#default', window.parent.document).html());
                //在iframe中调用父页面中定义的变量
                alert(parent.value);
                //在iframe中调用父页面中定义的方法
                parent.sayhello();
            });
         
       function test() {
            alert('我是子页面!');
        }
    </script> </head> <body> <div>iframe子页面内容</div> </body> </html>
  • 相关阅读:
    Memo
    list查询记录时页面变成空白
    get the mail ids of the group members
    ui action(server side) change column value
    catalog item 时间按照指定形式输出
    select box 联动
    lookup select box和select box 联动
    函数二--递归
    函数一
    指针3
  • 原文地址:https://www.cnblogs.com/gxp69/p/7511435.html
Copyright © 2011-2022 走看看