子页面(son.cshtml):
<script>
   function aa(){alert('父页面调用了子页面')}
</script>
<input id="son" type="button" value="son"/>父页面:
<script>
   function bb(){alert('子页面调用了父页面')}
</script>
<iframe id="fa" src="son.cshtml" display="width:400px;height:200px"/>
<input id="father" type="button" value="father"/>怎么让父页面点击id为father的button触发子页面的js的aa(),让子页面点击id为son的button触发父页面的js的bb()。如果用jquery怎么调用?我试过找不到类似的方法。
原来子页面用parent.bb()和父页面用fa.aa()在IE下可以成功,但在火狐下不行,怎么弄啊,跪求!!!

解决方案 »

  1.   

    http://hi.baidu.com/dcbt/blog/item/a46fc5cee6875435f8dc61f9.html
      

  2.   

    1.html
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script type="text/javascript">
    function a(){
    alert("调用父页面")
    }window.onload = function()
    {
    document.getElementById("father").onclick = function()
    {
    window.frames["fa"].b()
    };
    };
    </script></head><body><iframe id="fa" name="fa" src="2.html" style="width:400px;height:200px;"></iframe>
    <input id="father" type="button" value="father"/></body>
    </html>
    2.html
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script type="text/javascript">
    function b(){
    alert("调用子页面")
    }
    window.onload = function()
    {
    document.getElementById("son").onclick = function()
    {
    window.parent.a()
    };
    };
    </script></head><body>
    <input id="son" type="button" value="son"/></body>
    </html>
      

  3.   

    楼主可以试试下面的方法,不过要放在IIS里或其他server里测试.不能直接在本地用,有权限问题.
    我在Chrome16,FireFox3.6里,是可以的.Parent.html
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
    function btnParent_Click(){
    $('#iframe1').get(0).contentWindow.test();
    }function test(){alert('You are calling parent method!');}
    </script>
    <input type='button' id='btnParent' value='Parent' onclick='btnParent_Click();' />
    <iframe id='iframe1' src='child.html' />Child.html<script>
    function btnChild_Click(){parent.test();}function test(){alert('You are calling child method!');}
    </script><input type='button' value='Child' onclick='btnChild_Click();' />