<frameset rows="107,*"> 
<frame src="1.html" name="frametop" />
<frameset name="ChangeRow" rows="*" cols="180,*">
    <frame src="2.html" name="frame1" />
    <frame src="3.html" name="frame2" />
</frameset> 
</frameset>如何用js选择frame1和frame2??
如果是IE的话,我知道可以这样:window.parent.frames[1]//选中frame1;
                              window.parent.frames[2]//选中frame2;
但在chrome中却会报错!
求解chrome中该如何选中???

解决方案 »

  1.   

    document.getElementsByTagName('frame')[1]
    document.getElementsByTagName('frame')[2]
      

  2.   

    补充下,如果这段语句在1.html中呢?
      

  3.   

    parent.frames["frame1"]
    parent.frames["frame2"]
    chrome下 可以的 
      

  4.   

    想问问选中之后如何继续选中其中的元素;
    像下面的代码依然不能在chrome中执行,ie里就可以。没懂为啥<p>First Frame</p>
    <script type="text/javascript">
    function display(){
    parent.frames["frame1"].document.getElementById('b').style.backgroundColor='red';
    }
    </script>
    <input type="button" value="button" onclick="display()" />
      

  5.   

    http://topic.csdn.net/u/20111118/14/a82554b8-9f86-4b01-8d29-96006dc84e79.htmlcontentWindow
    contentDocument
      

  6.   

    上面的代码 chrome测下来可以的, 应该是 其他问题
      

  7.   

    chrome里报错说:
    Uncaught TypeError:Cannot call method'getelementById' of undefined
      

  8.   

    我发下全部文件你看看:
    文件名:testFrame.html<!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>
    <frameset rows="107,*"> 
    <frame src="1.html" name="frametop" />
    <frameset name="ChangeRow" rows="*" cols="180,*">
        <frame src="2.html" name="frame1" />
    <frame src="3.html" name="frame2" />
    </frameset> 
    </frameset>
    <body>
    <script type="text/javascript"></script>
    </body>
    </html>
    文件名:1.html<!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>
    <div id="a">
    <p>First Frame</p>
    <script type="text/javascript">
    function display(){
    parent.frames["frame1"].document.getElementById('b').style.backgroundColor='red';
    }
    </script>
    <input type="button" value="button" onclick="display()" />
    </div>
    </body>
    </html>文件名:2.html<!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>
    <div id="b">
    <p>Second Frame</p>
    </div>
    </body>
    </html>文件名:3.html<!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>
    <div id="c">
    <p>Third</p>
    </div>
    </body>
    </html>
      

  9.   

    上面的代码 用Chrome 15.0测下来没问题呀
      

  10.   

    啊,不会吧,你点了button后能变颜色?
      

  11.   

    奇怪了?!我这里,ff,ie,opera都能正常运行,就是chrome报错。纠结。。
      

  12.   


    chrome上传到服务器上就好了