zoukankan      html  css  js  c++  java
  • Js/Jquery获取iframe中的元素 在Iframe中获取父窗体的元素方法

    在web开发中,经常会用到iframe,难免会碰到需要在父窗口中使用iframe中的元素、或者在iframe框架中使用父窗口的元素

    js

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

    1、

    格式:window.frames["iframe的name值"].document.getElementByIdx_x("iframe中控件的ID").click();

    实例:window.frames["ifm"].document.getElementByIdx_x("btnOk").click();

    2、

    格式:

    var obj=document.getElementByIdx_x("iframe的name").contentWindow;

    var ifmObj=obj.document.getElementByIdx_x("iframe中控件的ID");

    ifmObj.click();

    实例:

    var obj=document.getElementByIdx_x("ifm").contentWindow;

    var ifmObj=obj.document.getElementByIdx_x("btnOk");

    ifmObj.click();

    在iframe中获取父窗口的元素

    格式:window.parent.document.getElementByIdx_x("父窗口的元素ID").click();

    实例:window.parent.document.getElementByIdx_x("btnOk").click();

    jquery

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

    1、

    格式:$("#iframe的ID").contents().find("#iframe中的控件ID").click();//jquery 方法1

    实例:$("#ifm").contents().find("#btnOk").click();//jquery 方法1

    2、

    格式:$("#iframe中的控件ID",document.frames("frame的name").document).click();//jquery 方法2

    实例:$("#btnOk",document.frames("ifm").document).click();//jquery 方法2

    在iframe中获取父窗口的元素

    格式:$('#父窗口中的元素ID', parent.document).click();

    实例:$('#btnOk', parent.document).click();

  • 相关阅读:
    Python: Best Way to Exchange Keys with Values in a Dictionary?
    install pymssql on centos
    centos 5.5 deploy full procedure
    centos 5.5 deploy full procedure
    change defaut python to 2.6.5 on centos
    Python: Best Way to Exchange Keys with Values in a Dictionary?
    install eventlet ,redis,dreque on centos
    install freetds on centos
    use alias
    install eventlet ,redis,dreque on centos
  • 原文地址:https://www.cnblogs.com/jearay/p/4790956.html
Copyright © 2011-2022 走看看