js子窗口之间互相调用,top在捣乱

index.html  总体框架显示:

<html xmlns="http://www.w3.org/1999/xhtml">  

    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>无标题文档</title>  
    <script type="text/javascript">  
        function ppp(){  
        
          alert(window.frames ["top"].aaa());
         }
    </script>  
    </head>  
      
        <frameset rows="18%,*"   framespacing="0">  
            <frame src="top.html" name= "top" scrolling="No" noresize="noresize"   frameborder="no"/>  
              
              
             <frameset cols="70%,*"> 
                  
                <frame src="left.html"  name="left"  scrolling="No" noresize="noresize" title="leftFrame"  frameborder="no"/>  
                <frame src="right.html" name="right"  scrolling="auto" noresize="noresize"  title="message" frameborder="no"/>   
            </frameset>      
              
         </frameset>  
        <noframes></noframes>  
    <body>     
    </body>  

    </html>  



top.html 上部界面显示:

 <html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>top</title>  
    <script type="text/javascript">  
        function aaa(){
        var str="hello";
          alert(str);
         }
    </script>  
    </head>  
     
    <body bgcolor="#CCCCFF">  
    top  
    <div id="test">aaaaaaaaaaaaa</div>
    </body>  
    </html>  


left.html 左侧界面显示:

<html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>left</title>  
    </head>  
    <script type="text/javascript">  
        function test1(){  
       parent.ppp();
            }  
    </script>  
    <body bgcolor="#0099FF">  
    left  
    </body>  
    <input type="button" οnclick="test1()" value="调用top" />  
    </html>  

right.html    右侧界面显示:

    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
    <title>right</title>  
    </head>  
      
    <body bgcolor="#99CC99">  
    right  
    </body>  
    </html> 

目的是通过left界面调用到top的函数,方法是先调用父窗体index的函数ppp(),再通过ppp来调用top的ttt()函数,试了各种办法都不行,最后我发现left可以调用right的函数,却不可以调用top的函数,我开始认为是frameset的原因,第二个frameset将top和left分开了,但我试着将right和top调换位置,left竟然还不能调用top的函数,我逐渐对比right.html和top.html的内容,最后试着将top换了个名字,神奇般的可以了!我想top应该是一个保留关键字吧,我将top改为tt即可运行成功。

ps:(其实,left调用top还可以这么写:parent.window.frames["tt"].aaa(),即将left调用index和index调用top合二为一了。)



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值