隨筆 - 117  文章 - 72  trackbacks - 0

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

          常用鏈接

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

          訂閱

          訂閱

          留言簿(7)

          隨筆分類(130)

          隨筆檔案(123)

          搜索

          •  

          積分與排名

          • 積分 - 156006
          • 排名 - 389

          最新評論

          作者: 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 天堂露珠 閱讀(566) 評論(0)  編輯  收藏 所屬分類: Web
          主站蜘蛛池模板: 桂林市| 新和县| 绥德县| 克东县| 连平县| 永登县| 武隆县| 上蔡县| 武功县| 霍州市| 乐都县| 灵山县| 乌拉特前旗| 孙吴县| 墨竹工卡县| 巫山县| 汽车| 文登市| 星座| 磴口县| 阳江市| 荃湾区| 惠来县| 邳州市| 玉树县| 邯郸县| 商河县| 龙里县| 彩票| 军事| 贡嘎县| 德清县| 闽侯县| 始兴县| 仁化县| 巢湖市| 黑龙江省| 阿合奇县| 新疆| 阳谷县| 永丰县|