js中frame的操作問題

來源:互聯網
上載者:User

標籤:blog   http   ar   sp   2014   on   問題   log   bs   

這裡以圖為例,在這裡把frame之間的互相操作簡單列為:1變數2方法3頁面之間元素的互相擷取。

A  首先從 父(frameABC)------->子(frameA,frameB,frameC)

    a1 : 訪問變數名name

          假如在frameABC中操作那麼可以:

           window.frames("frameA").contentWindow.name

           或者document.getElementById("frameA").contentWindow.name

           或者jquery:window.$("#frameA")[0].contentWindow.name

    a2:存取方法func

           假如在frameABC中操作那麼可以:             

            window.frames("frameA").contentWindow.func();

           或者document.getElementById("frameA").contentWindow.func();

           或者jquery:window.$("#frameA")[0].contentWindow.func();

    a3:訪問子頁面元素:username

            假如在frameABC中操作那麼可以:             

            window.frames("frameA").contentWindow.document.getElementById("username");

           或者document.getElementById("frameA").contentWindow.document.getElementById("username");

           或者jquery:window.$("#frameA")[0].contentWindow.$("#username");

B 然後從子(frameA,frameB,frameC)------------>到父(frameABC)

     b1:訪問父頁面變數name,假如在frameA中(子頁面)操作那麼可以:

          window.parent.name;

     b2:訪問父頁面方法func,假如在frameA中(子頁面)操作那麼可以:

          window.parent.func();

     b3:訪問父頁面元素username,假如在frameA中(子頁面)操作那麼可以:
          window.parent.$("#username")

      或者:window.parent.document.getElementById("username");

------------------------------------------------------------------------------

總結:frame只是一個頁面架構,要想操作子frame中的元素都需要首先進入到window或者contentWindow。從子頁面訪問父頁面,需要計算好父子關係,分幾層結構。

        在網上看了其他文章,談到有關頁面載入的問題。大概意思是在子frame頁面還沒載入出來就進行元素操作,會引起bug,有興趣的可以在下面寫寫自己的見解。

js中frame的操作問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.