tinguo002

           

          jQuery操作Frame(iFrame)

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

          沒找到很好的方法
          只好用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.

          我的代碼
          $('#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的id
          document.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存在時,這個方法還是很有用的。


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



          歡迎大家訪問我的個人網站 萌萌的IT人

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


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 固安县| 共和县| 罗城| 桐庐县| 渑池县| 平昌县| 康马县| 大连市| 邢台市| 中江县| 伊宁县| 杭州市| 钦州市| 平乐县| 琼结县| 石河子市| 视频| 忻州市| 额济纳旗| 楚雄市| 灵川县| 江都市| 宜都市| 杭锦后旗| 宁海县| SHOW| 莎车县| 苍梧县| 广宗县| 县级市| 忻城县| 迁西县| 田东县| 油尖旺区| 简阳市| 乌兰县| 怀宁县| 陆良县| 丹阳市| 南岸区| 叶城县|