您的位置:首页 > Web前端 > JavaScript

js父子窗口(二)

2015-11-04 21:15 519 查看
本文主要通过例子介绍父子窗口传递参数。

父窗口:

<!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"   onclick="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"   onclick="test_parent();"   value="提交">

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: