这几天用到了框架,需要在2个页面之间传递变量(用Javascript),搞了好久,终于可以了,特地记下来。
frame.htm
<HTML>
<HEAD>
<TITLE>* Place title here *</TITLE>
</HEAD>
<FRAMESET COLS="24%,76%">
<FRAME SRC="input.htm" NAME="leftframe">
<FRAME SRC="display.htm" NAME="rightframe">
</FRAMESET>
<NOFRAMES>
<!-- Place text here for browsers which do not support frames -->
</NOFRAMES>
</HTML>
input.htm
<HTML>
<META Created with Antechinus JavaScript Editor >
<HEAD>
<TITLE> *** Place Title Here *** </TITLE>
<script language="JavaScript1.2">
function copyValue() {
var name = parent.frames['rightframe'].document.form2.alias.value;
parent.frames['leftframe'].document.form1.name.value = name;
}
</script>
</HEAD>
<BODY BGCOLOR="white">
<form method="get" action="" name="form1">
<p> Name:<input type="text" value="jxyuhua" name="name" size="20"></p>
<p> <input type="button" value="Click" name="button" onClick="copyValue();"></p>
</form>
</BODY>
</HTML>
display.htm
<HTML>
<META Created with Antechinus JavaScript Editor >
<HEAD>
<TITLE> *** Place Title Here *** </TITLE>
</HEAD>
<BODY BGCOLOR="white">
<form method="get" action="" name="form2">
<p> Alias:<input type="text" value="123456" name="alias" size="20"></p>
</form>
</BODY>
</HTML>