zoukankan      html  css  js  c++  java
  • JS中子页面父页面方法 变量相互调用

     (1)子页面调用父页面的方法或者变量:

        window.parent.方法()或者变量名
        例如:想在子页面中得到 id 为 aaa 的文本框的值
        window.parent.$("#aaa").val();//这种写法的前提是引用了jquery
        window.parent.getElementById("aaa").value; //js的写法

    (2)父页面调取子页面 

       主要是通过contentWindow定位到子页面

       document.getElementById("childframe").contentWindow.childtest();
       //调取子页面中的 childtest 方法 js 的写法
       var childWindow = $("#addFrame")[0].contentWindow;    //获取子窗体中的对象
       childWindow.formSubmit();     //调取子页面的formSubmit方法 jquery的写法
       //注释:其中 childframe和addFrame 都时iframe的id

    (3). JS关闭父iframe窗口

    function cancel() {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
           parent.window.location.href = document.referrer;   //刷新父页面
           parent.layer.msg(resp.msg, { offset: '300px' });
     

  • 相关阅读:
    apollo使用场景2
    我问问
    洛谷 P3979 遥远的国度
    小技巧—对拍和输出文件的比较
    洛谷 P6850 NOI
    小技巧—双向边快速枚举
    ZJOI 2008 骑士
    小技巧—指数形式的枚举
    小技巧—滚动数组
    刷题心得—背包问题的枚举方式
  • 原文地址:https://www.cnblogs.com/weimingxin/p/8963819.html
Copyright © 2011-2022 走看看