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

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

    window.parent.方法()或者变量名
    window.parent相当于定位到父页面 之后的操作和在父页面中写代码一样写

    window.parent.aa();//调取aa函数
    window.parent.bb;//调取bb变量
    
    例如:想在子页面中得到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
    

      

  • 相关阅读:
    hdu4726
    hdu2709
    hdu4706
    hdu4715
    快速幂取模
    快速幂
    asp.net中页面传值
    微信小程序支付
    sql 查询重复记录值取一条
    bower使用
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/6155789.html
Copyright © 2011-2022 走看看