zoukankan      html  css  js  c++  java
  • 获取父窗口元素或者获取iframe中的元素(相同域名下)

    jquery方法

    在父窗口中获取iframe中的元素

    //方法1
    $("#iframe的ID").contents().find("iframe中的元素");
    //实例:
    $("#ifr").contents().find("#someid");
    //方法2
    $("#iframe中的控件ID",document.frames("frame的name").document);
    //实例
    $("#someid",document.frames("ifr").document);

    在iframe中获取父窗口的元素

    //方法
    $('#父窗口中的元素ID', parent.document); //实例 $('#someid', parent.document);

    js方法

    在父窗口中获取iframe中的元素

    //方法
    window.frames["iframe的name值"].document.getElementById("iframe中控件的ID");
    //实例
    window.frames["ifr"].document.getElementById("someid");

    在iframe中获取父窗口的元素

    //方法
    window.parent.document.getElementById("父窗口的元素ID");
    //实例
    window.parent.document.getElementById("someid");

    欢迎补充!

  • 相关阅读:
    Vue3.0
    Vue
    Vue
    Vue3.0
    Vue
    Vue
    Vue
    Vue
    Vue3.0
    万字长文|十大基本排序,一次搞定!
  • 原文地址:https://www.cnblogs.com/sysg/p/6549096.html
Copyright © 2011-2022 走看看