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)

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 南皮县| 黄山市| 故城县| 黑水县| 遵义县| 永春县| 临夏县| 石嘴山市| 龙川县| 资兴市| 永修县| 江都市| 罗江县| 鄂托克前旗| 双鸭山市| 弥渡县| 车致| 明溪县| 利川市| 礼泉县| 石泉县| 屏东市| 拜城县| 台中县| 视频| 白河县| 巧家县| 叙永县| 洪湖市| 湖州市| 抚顺市| 城步| 花莲县| 保靖县| 遂昌县| 嘉峪关市| 贵溪市| 无棣县| 兴城市| 石城县| 蓬溪县|