js中frame的操作问题

这里以图为例,在这里把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,有兴趣的可以在下面写写自己的见解。

 

语句1. window.parent.frames[1].location.reload(); 
语句2. window.parent.frames.bottom.location.reload(); 
语句3. window.parent.frames["bottom"].location.reload(); 
语句4. window.parent.frames.item(1).location.reload(); 
语句5. window.parent.frames.item('bottom').location.reload(); 
语句6. window.parent.bottom.location.reload(); 
语句7. window.parent['bottom'].location.reload(); 

转载于:https://www.cnblogs.com/lovebaoqiang/p/pathFinding.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值