模态窗口的运用

1   在主窗体

<!DOCTYPE html>
<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 testModalDialog()
{
var p = new Object();
p.name = "chengdong";
var res = window.showModalDialog("2.html", p);
alert("返回值" + res);

}

</script>
</head>
<body>
<a href="javascript:testModalDialog()">弹出模态窗口</a>
</body>
</html>

2  弹出的窗体

<!DOCTYPE html>
<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">

var obj = window.dialogArguments;
alert("你传递的参数是"+obj.name);
function closeWin()
{
window.returnValue = document.getElementById("txtName").value;
window.close();
}
</script>
</head>
<body>
模态窗体赶回值给父窗体
<input type="text" id="txtName"/>
<input type="button" value="关闭" onclick="closeWin()" />
</body>
</html>

原文地址:https://www.cnblogs.com/cdaq/p/3921574.html