posts - 3,  comments - 12,  trackbacks - 0

          <1> js或者jQuery訪問頁面中的框架iframe.
          注意:框架內的頁面是不能跨域的! 假設有兩個頁面,在相同域下.

           

          假設:父窗口  index.html ,有 id 為 subifrm 的 iframe

           

          1. 在index.html執行JS直接訪問子窗口中某元素 :

          document.getElementById('subifrm').contentWindow.document.getElementById('test').style.color='red'  

          2. 利用jquery 來訪問子窗口

          $("#subifrm").contents().find("#test").css('color','red');

          ====================================================================

          ====================================================================

           

          <2> 用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"); 

          ====================================================================

          ====================================================================

           

          <3> 使用jquery操作iframe

          1 頁面里有兩個ifame

          <iframe id="leftiframe"></iframe>     
          <iframe id="mainiframe></iframe>    
          <iframe id="leftiframe"></iframe>  
          <iframe id="mainiframe></iframe> 

          leftiframe中jQuery改變mainiframe的src代碼:

          $("#mainframe",parent.document.body).attr("src","http://www.baidu.com"

          2、 如果內容里面有一個ID為mainiframe的ifame

          <iframe id="mainifame"></ifame>     
          <iframe id="mainifame"></ifame> 

          ifame包含一個someID

          <div id="someID">you want to get this content</div>     
          <div id="someID">you want to get this content</div>

          得到someID的內容

          $("#mainiframe").contents().find("someID").html();或者$("#mainiframe").contains().find("someID").text();   
          $(
          "#mainiframe").contents().find("someID").html();或者$("#mainiframe").contains().find("someID").text(); 

          $(
          "#mainiframe").contents().find("someID").html();或者$("#mainiframe").contains().find("someID").text(); 


          2 、如上面所示
             leftiframe中的jQuery操作mainiframe的內容someID的內容

          $("#mainframe",parent.document.body).contents().find("someID").html();或者 $("#mainframe",parent.document.body).contents().find("someID").val();

          source:http://suan2046.javaeye.com/blog/575421
          posted on 2011-03-07 14:14 [ 王志偉 ] 閱讀(897) 評論(0)  編輯  收藏

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


          網站導航:
           

          <2025年8月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          常用鏈接

          留言簿(1)

          隨筆檔案(3)

          文章檔案(29)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 土默特右旗| 友谊县| 开平市| 巴彦淖尔市| 湘阴县| 明水县| 怀安县| 嘉黎县| 乌拉特中旗| 岱山县| 永昌县| 如皋市| 晴隆县| 教育| 桐城市| 茂名市| 石棉县| 仁寿县| 五峰| 新和县| 都匀市| 吴旗县| 新源县| 织金县| 南召县| 平遥县| 乌恰县| 武城县| 米易县| 富阳市| 昌邑市| 西乌珠穆沁旗| 博爱县| 北票市| 定安县| 阳谷县| 务川| 琼海市| 鄂尔多斯市| 屏东县| 沂南县|