程晓晖

博客园 首页 新随笔 联系 订阅 管理

父窗体代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function OpenChildWindow()
{
   var obj = new Object();
 obj.name = document.getElementById('txtInput').value;
 var result = window.showModalDialog('2.html',obj);
 document.getElementById('txtInput').value = result.name;
}
</script>
</head>
<body>
<input type="text" id="txtInput" />
<input type="button" value="OpenChild" onclick="OpenChildWindow()" />
</body>
</html>

子窗体代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
//接收父窗体传来的值
function Load()
{
 var obj = window.dialogArguments;
 document.getElementById('txtInput').value=obj.name ;
}
//向父窗体返回值
function SetValue()
{
 var obj = new Object();
 obj.name = document.getElementById('txtInput').value;
 window.returnValue = obj;
 window.close();
}
</script> 
</head>
<body onload="Load()">
<input type="text" id="txtInput" />
<input type="button" value="SetFather" onclick="SetValue()" />
</body>
</html>

posted on 2010-11-13 21:12  fumen  阅读(153)  评论(0编辑  收藏  举报