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>
轉載地址:http://blog.sina.com.cn/s/blog_586b6c0501008h9o.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM