比如a页面有个js1,b页面有个js2,a和b页面有共同的父页面c。现在要从js1调用js2,有什么方法可以实现?

解决方案 »

  1.   

    parent.htm
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>parent</title>
    <script>
    var a = window.open("a.htm");
    var b = window.open("b.htm");
    </script>
    </head><body></body></html>
    a.htm
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>a</title>
    <script>
    function getBfunction(){
    alert(window.opener.b.bFunction());
    }
    </script>
    </head><body>
    <input type="button" onclick="getBfunction()" value="调用b.htm的方法"/>
    </body></html>b.htm
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>b</title>
    <script>
    function bFunction(){
    return "这里是b.htm...";
    }
    </script>
    </head><body></body></html>
      

  2.   

    lihui_shine
     
    (浪尖赏花) 
    如果我abc三个页面是frameset,c是链接index页面,ab分别是frame里面的src比如
    <frameset cols="160,*" border="1">
     <frame name="leftFrame" src="c.jsp" frameborder="0">
     <frameset rows="25,*" border="1">
     <frame name="pathFrm" src="./a.jsp" frameborder="0">
     <frame name="mainFrm" src="./b.jsp" frameborder="0">
     </frameset>
      

  3.   

    把 Javascript 放在主页,在子页调用:Complex.js 定义 Complex() <head>
    <script src="Complex.js"></script>
    </head>
    <frameset rows="50%,50%">
      <frame name="frame1" src="frame1.html">
      <frame name="frame2" src="frame2.html">
    </frameset> 
    在子页frame1 frame2 调用主页定义的 Complex() 函数:var Complex = top.Complex;
    var c = new Complex(1,2);