子窗口向父窗口传值

方案1:

parent01.html
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>父窗口</title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<script type="text/javascript">
function addwindow() {
var href = "/demo/window/son01.html";
window.open(href, "newwindow", "height=200,width=400,toolbar=no,menubar=no,scrollbars=no,resizable=no, location=no,status=no");
}
function add(id, textvalue) {
document.getElementById(id).value = textvalue;
}
</script>
<body>
<input id="newId" type="text"><br>
<input type="button" value="addwindow" onclick="addwindow()">
</body>
</html>


son01.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>子窗口</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<script type="text/javascript">
function test() {
var textValue;
for (var i = 0; i < document.getElementById("newId").length; i++) {
if (document.getElementById("newId").options[i].selected) {
textValue = document.getElementById("newId").options[i].text;
break;
}
}
window.opener.add("newId", textValue);
self.close();
}
</script>

<BODY>
<form id="form1">
<select id="newId">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="button" value="submit" onclick="test()">
</form>
</BODY>
</HTML>


方案2

parent02.html
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>父窗口</title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
<script type="text/javascript" src="/js/jquery/jquery-1.8.1.min.js"></script>
<script language="javascript" src="/js/com.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function () {
$("#addwindow").click(function(e) {
var href = "/demo/window/son02.html";
var textValue = openDialog(href,750, 350, "yes", e);
if (textValue != "" && textValue != null) {
add("newId",textValue);
}
});
});
function add(id, textvalue) {
document.getElementById(id).value = textvalue;
}
</script>
<body>
<input id="newId" type="text"><br>
<input type="button" id="addwindow" value="addwindow">
</body>
</html>


son02.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>子窗口</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<script type="text/javascript">
function test() {
var textValue;
for (var i = 0; i < document.getElementById("newId").length; i++) {
if (document.getElementById("newId").options[i].selected) {
textValue = document.getElementById("newId").options[i].text;
break;
}
}
window.returnValue = textValue;
window.close();
}
</script>

<BODY>
<form id="form1">
<select id="newId">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="button" value="submit" onclick="test()">
</form>
</BODY>
</HTML>


[img]http://dl.iteye.com/upload/attachment/0083/8290/af78ac0c-a8ad-3b91-b9cb-aa373f674fa8.jpg[/img]

[img]http://dl.iteye.com/upload/attachment/0083/8292/f867f73c-86db-3373-91c6-51fc6dcd2232.jpg[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值