通过window.parent属性获得当前frame的父页面window对象,再通过window对象的frames集合来找到你想要的frame对应的window对象,然后就可以访问下面的document的各个子结点了。举例来讲,你在一个frame的一个onclick事件里面写的代码可能是:
window.parent.frames["frame2"].document.all["text1"].value = "xxx"
以上代码就改变了frame2下面的一个text1的文本框的值。

解决方案 »

  1.   

    ///index.html///////////////////////////
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><frameset rows="226,*" cols="*" framespacing="0" frameborder="yes" border="2">
      <frame src="top.html" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
      <frame src="bottom.html" name="mainFrame" id="mainFrame" title="mainFrame" />
    </frameset>
    <noframes><body>
    </body>
    </noframes></html>///top.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>
    <table width="340" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
      <!--DWLayoutTable-->
      <tr>
        <td width="340" height="173" align="center" valign="middle"><span id="myspan"></span></td>
      </tr>
    </table>
    </body>
    </html>///bottom.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>
    <script language="javascript" type="text/javascript">
    function alertit(){ parent.frames['topFrame'].myspan.innerHTML=forma.textfield.value;

    //alert(forma.textfield.value);return false;
    }
    </script>
    </head><body>
    <table width="397" border="0" cellpadding="0" cellspacing="0" align="center">
      <form action="" method="post" name="forma">
      <tr>
        <td width="397" height="95" align="center" valign="middle">
    <input name="textfield" type="text" value="看上面的页面变化!!" /></td>
      </tr>
      <tr>
        <td height="86" align="center" valign="middle">
    <input type="button" name="Submit" onclick="return alertit()" value="改变" /></td>
      </tr>
      </form>
    </table>
    </body>
    </html>