本帖最后由 mingfish 于 2009-10-14 17:45:02 编辑

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <script type="text/javascript" src="../My Documents/未命名站点 1/jquery.js"></script>
    <script>
    //以下代码无效
        $(function(){
    var con =  document.getElementById('con').contentWindow;
    con.document.getElementById('mylink').onclick = function(){
    $("#main").attr("src","http://google.com");
    };
        })
    </script>
    <div>
        <iframe id="con" src="control.html" width=200 height=200>
        </iframe>
    </div>
    <div>
        <iframe id="main" src="http://baidu.com" width=200 height=200></iframe>
    </div>
    </body>
    </html>
      

  2.   

    测试无效,
    document.getElementById('con')
    没有#con啊
      

  3.   


    <meta content="text/html; charset=gb2312" http-equiv="Content-Type"/>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script>
    //以下代码有效
        $(function(){
    var win=document.getElementById("ifr1").contentWindow;
    win.document.getElementById("mylink").onclick=function() {
    document.getElementById("main").src="http://www.google.com";
    }
        })
    </script>
    <div>
        <iframe src="control.html" width=200 height=200 id="ifr1">
        </iframe>
    </div>
    <div>
        <iframe id="main" src="http://baidu.com" width=200 height=200></iframe>
    </div>
      

  4.   


    你是把我的页面都复制下来了吗?你仔细看看我2楼的HTML 怎么可能没有con这个ID我都测试过了~·没问题~·
      

  5.   


    <div>
        <iframe id="con" src="control.html" width=200 height=200>
        </iframe>
    </div>
      

  6.   

    应该是点击在第一个iframe里面的Button吧?
    把下面的代码放到control.html里面。
            <script type="text/javascript">
                $(function() {
                    $("#mylink").click(function() {
                        $("window.parent.document").find("#main").attr("src", "http://google.com");
                    })
                })
    </script>
    <a id="mylink" href="#">google</a>
      

  7.   

    选择器测试的时候弄错了:
            $(function() {
                $("#mylink").click(function() {
                    $(window.parent.document).find("#main").attr("src", "http://google.com");
                })
            })
    </script>
      

  8.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html>
      <head>
        <title>jj</title>
        <script type="text/javascript">
            function google()
            {
                self.parent.frames["main"].location.href="http://www.g.cn";
            }
        </script>
    </head>
      <body>
        <div>
          <button id="mylink" onclick="google()">控制第二个iframe</button>
        </div>
      </body>
    </html>