jQuery操作Frame(iFrame)

來源:互聯網
上載者:User

標籤:

沒找到很好的方法
只好用DOM方法與jquery方法結合的方式實現了

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中測試通過 回去你自己試試吧
剛才google到的,補充一下

I beat my head against this wall for quite some time.

Try this:
$("#myid", top.document);
the top.document tells the selector to target the myid element which
exists in the topmost document (your parent page). In order for this
to work, jquery must be loaded in the file which is viewed through the
iframe.

My Code
$(‘#parentElem‘, top.document).append(‘<div class="imgbox" id="imgbox"><img class="img" src="pp.png" id="img"></div>‘);

upc不是說了麼
1.在父視窗中操作 選中IFRAME中的所有單選鈕
$(window.frames["iframe1"].document).find("input[@type=‘radio‘]").attr("checked","true");

那選擇id自然就是依然使用find方法
$(window.frames["iframe1"].document).find("#id")

實際樓上上的方法本質上在Jq內部也是調用了find方法 父表單調用IFrame中的方法(right)為ifram的iddocument.frames["right"].expand();父表單:parent;

子表單:opener;(window.opener.reload();)

上面的都是網上摘的,下面補充很重要的一點:

你可能已經注意到了,上面提及的都是自上而下的selector方法,也就是從上級window尋找下級window(包括iframe建立的window),如果我們希望從下級window,比如希望通過iframe中的window找到iframe的parentNode,可以這樣:

var parentFrame=null;
if(window!=window.top){parentFrame=window.frameElement.name};

往下就可以直接$(.....

當然,一個topwindow中僅僅包含一個iframe時我們沒有必要這樣,但當若干iframe存在時,這個方法還是很有用的。

jQuery操作Frame(iFrame)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.