js中实现子页面向父页面中赋值(两种方法)

  (方法一)

父页面:
<input  id="input1" type="text"/>
<a href="javascript:window.open('test1.aspx');void(0)">弹出新的子窗口</a>

子页面:
<input id="input2" type="text" />
<input id="bt" type="button" onclick="doit();" value="更新父窗口的内容"/>
<script type="text/javascript" language="javascript">
function doit()
{
  var _value=document.getElementByIdx('input2').value;
  window.opener.document.getElementByIdx('input1').value=_value;
}
</script>

(方法二)

父页面:
<input id="input1" type="text" />
<a href="javascript:GetReturnValue();void(0)">弹出新的模态子窗口</a>
<script type="text/javascript" language="javascript">
 function GetReturnValue()
 {
     var temp= window.showModalDialog("test1.aspx","","center=yes;help=no;status=no");
     document.getElementByIdx('input1').value = temp;
 }
</script>

子页面:
<input id="input2" type="text" />
<input id="bt" type="button" onclick="doit();"  value="更新父窗口的内容"/>
<script type="text/javascript" language="javascript">
function doit()
{
  var _value=document.getElementByIdx('input2').value;
  window.returnValue =_value;
  window.close();
}
</script>