zoukankan      html  css  js  c++  java
  • iframe子页面获取父页面元素的方法

    在iframe子页面获取父页面元素

     代码如下:

    $.('#objld', parent.document); 
    在父页面获取iframe子页面的元素

     代码如下:

    $("#objid", document.iframes('iframe').document) 

     代码如下:

    $(document.getElementById('iframeId').contentWindow.document.body).html() $(document.getElementById('iframeId').contentWindow.document.body).html()


    显示iframe中body元素的内容

     代码如下:

    $("#testId", document.frames("iframename").document).html()

    (1)父页面获取iframe中的元素值:

    Js代码  
    1.//根据iframe的id获取对象   
    2.var i1 = window.frames['iframeId'];   
    3.//var iframe =window.frames[0];也可以   
    4.//获取iframe中的元素值   
    5.var val=i1.document.getElementById("t1").value  
    //根据iframe的id获取对象
    var i1 = window.frames['iframeId'];
    //var iframe =window.frames[0];也可以
    //获取iframe中的元素值
    var val=i1.document.getElementById("t1").value

    (2)在iframe中获取父页面中的元素值:

    Js代码  
    1.var val = parent.document.getElementById("txt1");   
    var val = parent.document.getElementById("txt1");

    (3)a包含2个iframe分别为b,c,现在从b中获取c中的元素的值:

    Js代码  
    1.var i1 = parent.window.frames['iframeId'];   
    2.var val = i1.document.getElementById("text1").value;  
    var i1 = parent.window.frames['iframeId'];
    var val = i1.document.getElementById("text1").value;

  • 相关阅读:
    AOP Aspect 统一日志、异常处理、数据格式
    java基本成员默认值
    Jackson ObjectMapper
    logstash 安装 jdbc-output出错
    ElasticSearch定时删除数据(非时间结尾规律索引)
    docker安装部署
    K8s 使用helm 安装 EFK和ELK分布式日志分析系统系列(es版本:6.7.0;)
    JWT 验证
    JS查找数组中元素index
    oracle not in 失效
  • 原文地址:https://www.cnblogs.com/xiaoleiel/p/8308808.html
Copyright © 2011-2022 走看看