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 一堣而安 閱讀(814) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 滦南县| 清涧县| 治县。| 孟津县| 上杭县| 肃北| 九龙县| 明溪县| 扎囊县| 石楼县| 玉环县| 城口县| 五原县| 循化| 彩票| 崇文区| 同德县| 六枝特区| 清涧县| 桂东县| 鄂州市| 枣强县| 贵州省| 项城市| 文安县| 湄潭县| 嘉善县| 兴海县| 北宁市| 那坡县| 东乡族自治县| 从江县| 许昌市| 秦安县| 金溪县| 凤庆县| 屏东市| 邢台市| 宜黄县| 五莲县| 林州市|