隨筆 - 117  文章 - 72  trackbacks - 0

          聲明:原創作品(標有[原]字樣)轉載時請注明出處,謝謝。

          常用鏈接

          常用設置
          常用軟件
          常用命令
           

          訂閱

          訂閱

          留言簿(7)

          隨筆分類(130)

          隨筆檔案(123)

          搜索

          •  

          積分與排名

          • 積分 - 156420
          • 排名 - 390

          最新評論

          作者: Winty
          時間: 2008-12-26

          在網上找到在IE下操作IFrame內容的代碼:
             
          document.frames["MyIFrame"].document.getElementById("s").style.color="blue";

          但是這在Firefox下無效。
          所以,想到在Firefox下用FireBug來調試。經過調試發現在Firefox下可用以下代碼來實現:
             
          document.getElementById("MyIFrame").contentDocument.getElementById("s").style.color="blue";

          詳細代碼如下:
          TestIFrame.htm:

          <html>
          <head>
          <script type="text/javascript">
          function f(){
                  var doc;

                  if (document.all){//IE
                          doc = document.frames["MyIFrame"].document;
                  }else{//Firefox    
                          doc = document.getElementById("MyIFrame").contentDocument;
                  }

                  doc.getElementById("s").style.color="blue";
          }
          </script>
          </head>
          <body onload="f()">

          <iframe id = "MyIFrame" name = "MyIFrame" src = "MyIFrame.htm" width = "100" height="100">

          </body>
          </html>


          MyIFrame.htm:

          <h1 id = "s" style="color:red;" >內容<h1>

          附件內容:
          1.TestIFrame.htm
          2.MyIFrame.htm
          文章來源:http://wintys.blog.51cto.com/425414/123303

          [附件]:MyIFrame.zip
          posted on 2009-03-18 12:02 天堂露珠 閱讀(570) 評論(0)  編輯  收藏 所屬分類: Web
          主站蜘蛛池模板: 阳高县| 大新县| 辽宁省| 呼图壁县| 西贡区| 芒康县| 屯昌县| 察雅县| 朝阳区| 平昌县| 出国| 兰考县| 大理市| 镇安县| 崇礼县| 新余市| 中方县| 大关县| 岚皋县| 新竹市| 尼玛县| 财经| 徐州市| 利津县| 海兴县| 泾川县| 雅安市| 兴国县| 伊金霍洛旗| 尖扎县| 潮安县| 龙山县| 浦东新区| 密云县| 汉寿县| 通渭县| 苍南县| 玉林市| 海晏县| 望江县| 湛江市|