日期:2014-05-16  浏览次数:20457 次

用javascript实现父窗口与子窗体交互。
父页代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<html>
 <head>
  <title> new document </title>
 </head>
<script language="javascript" >
function opennew(){
window.open("deplist.html","mywin", "menubar=no,width=400,height=500,resizeable=yes");

}

</script>
 <body>
<form id="form1" >
Value:<input name="list" type="text" value="">
Text:<input name="dizhi" type="text" value="">
<input type="button" value="打开" onclick="opennew()">

</form>
  
 </body>
</html>



子页代码
<html>
<head></head>
<script language="javascript">
function setValue(){
   
var depcode = depfrm.subdepart.options[depfrm.subdepart.selectedIndex].value;
var depname = depfrm.subdepart.options[depfrm.subdepart.selectedIndex].text;
//alert(depcode);
//alert(depname);
self.opener.document.all.form1.list.value=depcode;
self.opener.document.all.form1.dizhi.value=depname;

window.close();
}

</script>
</html>
<body>
<form id="depfrm" >
<table width="200px">
<tr>

<select name="subdepart"  size="20" >
<option value="aaa">天涯</option>
<option value="aaa2">天涯2</option>
</select>
<br>
     <input type="button" onclick="setValue()" value="确定">
</tr>
</table>
</form>
</body>

</html>




其中,父窗页面你随便命名好了。这里子窗页面是deplist.html
对效果没影响只是怕到时候有人打不开.&__&