tinguo002

           

          jQuery操作Frame(iFrame)

          jQuery操作Frame(iFrame)
          2009年02月18日 星期三 19:57

          沒找到很好的方法
          只好用DOM方法與jquery方法結合的方式實現(xiàn)了

          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.

          我的代碼
          $('#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")

          實際樓上上的方法本質(zhì)上在Jq內(nèi)部也是調(diào)用了find方法
          父窗體調(diào)用IFrame中的方法(right)為ifram的id
          document.frames["right"].expand();
          父窗體:parent;

          子窗體:opener;(window.opener.reload();)

          上面的都是網(wǎng)上摘的,下面補充很重要的一點:

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

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

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

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


          轉載自:http://hi.baidu.com/51plan/blog/item/381ee57e4c328e3f0cd7daac.html



          歡迎大家訪問我的個人網(wǎng)站 萌萌的IT人

          posted on 2012-03-22 16:50 一堣而安 閱讀(814) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           

          導航

          統(tǒng)計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 杂多县| 颍上县| 屏山县| 密云县| 深州市| 敦煌市| 黎川县| 凤山县| 和林格尔县| 托里县| 河北区| 白沙| 闽清县| 济宁市| 西乡县| 岢岚县| 翼城县| 松江区| 东阳市| 休宁县| 勃利县| 象山县| 乌拉特前旗| 卢湾区| 商南县| 临沂市| 紫云| 奎屯市| 老河口市| 临江市| 商南县| 桐庐县| 班玛县| 辽宁省| 两当县| 奉化市| 金寨县| 吴旗县| 民勤县| 晋中市| 泉州市|