本文主要通过例子介绍父子窗口传递参数。
父窗口:
<!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=gb2312" />
<title>parent</title>
</head>
<body>
<input type ="text" id ="a">
<input type ="text" id ="b">
<input type ="text" id ="sum">
<h5>
<span id="comment" >222</span>
<br>
<input type="button" id="test" οnclick="var returnVal = window.showModalDialog('childWin_js.html',window,''); document.getElementById('sum').value = returnVal" value="点我">
</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=gb2312" />
<title>child</title>
<script language="javascript">
// 子窗口给父窗口赋值(模态)
function test_parent() {
// 获得父窗口的对象
var parent=window.dialogArguments;
parent.document.getElementById("comment").innerHTML = ' 计算完成 ';
var x = parent.document.getElementById('a').value;
var y = parent.document.getElementById('b').value;
window.returnValue=parseInt(x)+ parseInt(y);
window.close(); //关闭模态窗口
}
</script>
</head>
<body>
计算父画面的值,并返回
<br>
<input type="button" οnclick="test_parent();" value="提交">
</body>
</html>