[转]利用模式窗口:实现子、父窗体的相互传值

<!-- ======  父窗体,我取名为parentform.html  ==== -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>弹出窗口内录入数据确定后返回给父窗体--主窗体</title>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="qiujy">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">

<script language="javascript" type="text/javascript">
function doInput()
{
 var win = window.showModalDialog("Childform.html",window,"dialogWidth=500px;dialogHeight=300px;center=yes;status=no");
 if(win != null)
 {
  document.getElementById("parentTextBox").value = win;
 }
}
</script>

</head>
<body>在新弹出的窗体里输入数据,传输到父窗体.
<br/>
<br/>
<br/>
&nbsp;&nbsp;<input type="text" id="parentTextBox" /> <a href="javascript:doInput()">点这里弹出子窗体</a>
</BODY>
</HTML>

<!-- ============= 父窗体代码结束 =============  -->

<!-- ======= 子窗体:取名为childform.html  ======= -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title> 弹出窗口内录入数据确定后返回给父窗体--子窗体</title>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="qiujy">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<base target="_self">
</head>
<body topmargin="0" leftmargin="0" scroll="no">
</br>
&nbsp;&nbsp;<input type="text" id="childTextBox"/>
</br></br>
&nbsp;&nbsp;<a href="javascript:doPassToParent()">点这里返回</a>
</BODY>
</HTML>
<script language="javascript" type="text/javascript">
document.getElementById("childTextBox").value = window.dialogArguments.document.getElementById("parentTextBox").value;
function doPassToParent()
{
 if(document.getElementById("childTextBox").value.length <=0)
 {
  alert("请填写数据");
  return;
 }
 window.returnValue = document.getElementById("childTextBox").value;
 window.close();

}
</script>

<!-- ============= 子窗体代码结束 ============ -->

效果图

在子窗体的文本框中输入“把值返回到父窗体中”,点击“点这里返回”后:

posted @ 2012-06-27 13:57  琥珀光  阅读(129)  评论(0编辑  收藏  举报