html

本文介绍如何使用JavaScript实现父页面通过window.open()打开子页面,并从子页面向父页面回传值的方法。示例代码展示了如何在不刷新页面的情况下更新父页面的input域值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

父页面用window.open()打开子页面,子页面向父页面传值

分类: C#技术文章
2007.11.16 22:55 作者:menglongonline | 评论:0 | 阅读:0
父页面用window.open()打开子页面,子页面向父页面input域回传值(不刷新 参数的传递)

test.htm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<input name=uname>
<input type=button onclick=window.open("a.htm") value=选择>
</body>
</html>

 

------------------------------------------------------------------------------------------

a.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script>
function setvalue(v){
window.opener.document.all.uname.value=v//该值可改为由数据库获得
//window.opener.document.getElementById("test").innerHTML="由数据库获得"
opener=null;
self.close();
}

</script>
<body>
<select name=user>
<option value=人员1>人员1</option>
<option value=人员2>人员2</option>
<option value=人员3>人员3</option>
</select>
<input onclick=setvalue(user.value) type=button>
</body>
</html>

JAVA: 求一个画面间传值的JS例子~(急)

[此问题的推荐答案]
只知道可以弹出一个画面,然后 子画面显示父画面的值,然后把父画面关闭,代码如下:
A.html
<html>
<head>
<script language="javascript">
function go() {
window.open("B.html");
}
</script>
</head>
<body>
<input type="text" id="text1" /><br>
<input type="text" id="text2" /><br>
<input type="button" value="go" onclick="go()" />
</body>
</html>

B.html
<html>
<head>
<script language="javascript">
function onload() {
document.getElementById("text1").value = window.opener.document.getElementById("text1").value;
document.getElementById("text2").value = window.opener.document.getElementById("text2").value;
window.opener.close();
}
</script>
</head>
<body onload="onload()">
<input type="text" id="text1" /><br>
<input type="text" id="text2" /><br>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值