zoukankan      html  css  js  c++  java
  • HTML中嵌套的子frame如何访问父页面中的函数?

    我解决的办法,在父页面写了个函数,然后在frame页面调用父页面的函数,具体代码如下:

    父:function a(){}

    子frame:window.parent.a();

    问题迎刃而解,2020/04/20日补记:如果frame中的页面和父页面不同域。则需要进行跨域实现js代码互相调用。这种情况,往document.domain方向去调查。

     https://www.jb51.net/article/39486.htm

    参考1:http://m.php.cn/article/383528.html

    参考2:https://www.jb51.net/article/116273.htm

    附件:

    DOM方法:
    父窗口操作IFRAME:window.frames["iframeSon"].document
    IFRAME操作父窗口: window.parent.document

    jquery方法:
    在父窗口中操作 选中IFRAME中的所有输入框: $(window.frames["iframeSon"].document).find(":text");
    在IFRAME中操作 选中父窗口中的所有输入框:$(window.parent.document).find(":text");
    iframe框架的HTML:<iframe src="test.html" id="iframeSon" width="700″ height="300″ frameborder="0″ scrolling="auto"></iframe>

    1.在父窗口中操作 选中IFRAME中的所有单选钮
    $(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");

    2.在IFRAME中操作 选中父窗口中的所有单选钮
    $(window.parent.document).find("input[@type='radio']").attr("checked","true");
    iframe框架的:

    <iframe src="test.html" id="iframe1″ width="700″ height="300″ frameborder="0″ scrolling="auto"></iframe>

    1.在父窗口中操作 选中IFRAME中的所有单选钮
    $(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");

    2.在IFRAME中操作 选中父窗口中的所有单选钮
    $(window.parent.document).find("input[@type='radio']").attr("checked","true");
    iframe框架的:<iframe src="test.html" id="iframe1" width="700" height="300" frameborder="0" scrolling="auto"></iframe>
    IE7中测试通过

    Best Regards
  • 相关阅读:
    【LOJ】 #2015. 「SCOI2016」妖怪
    【LOJ】#2016. 「SCOI2016」美味
    【LOJ】 #2008. 「SCOI2015」小凸想跑步
    【LOJ】#2007. 「SCOI2015」国旗计划
    【LOJ】#2006. 「SCOI2015」小凸玩矩阵
    【LOJ】#2172. 「FJOI2016」所有公共子序列问题
    【LOJ】#2173. 「FJOI2016」建筑师
    【LOJ】#2174. 「FJOI2016」神秘数
    【LOJ】#2280. 「FJOI2017」矩阵填数
    【洛谷】P4585 [FJOI2015]火星商店问题
  • 原文地址:https://www.cnblogs.com/pecool/p/9192679.html
Copyright © 2011-2022 走看看