代码改变世界

js子窗口向父窗口传值

2012-08-28 19:14  hongjiumu  阅读(950)  评论(0编辑  收藏  举报

用opener

这是一个父窗口~

<html>
<head>
<title>
</title>
<script language="javascript">
function win(){
   window.open("login.html",null,"height=150,width=200");
}

</script>
</head>
<table id="t1">
<tr><td id="dd">user</td></tr>
<tr><td id="bb">sex</td></tr>
</table>
<input type="button" value="提交" onclick="win()"/>
</html>

 

下面是一个子窗口

<html>
<head>
<title>
</title>
<script language="javascript">
function win(){

   window.opener.document.all.dd.innerText=document.getElementByIdx("user").value;
   window.opener.document.all.bb.innerText=document.getElementByIdx("sex").value;

   window.close();
}

</script>
</head>
<body>
user:
<input type="text" name="user"/>
<br>sex:
<input type="text" name="sex"/>
<br>
<input type="button" value="提交" onclick="win()"/>
</body>
</html>