- 关于子窗口向父窗口传值并关闭子窗口问题
- 发布时间:2011-11-01 13:17:25 浏览数:14019 发布者:tznktg 设置字体【大 中 小】
点开父窗口(fu.html) ,点图片链接打开子窗口(zi.html) 子窗口有一条数据库记录(方便显示我直接写出来了),点这条记录会把这条记录的ID传到父窗口里。我以前都是在子窗口用到按钮提交可以实现关闭当前子窗口,用链接后这个方法就不行了。
问题:点链接后在新的当前窗口打开了父窗口,而不是把值传到了老的父窗口。
等待高手给指教,谢谢~~~~!
父窗口 fu.html
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>父窗口</title>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="bgc_table">
<tr>
<td width="33%" class="bgc_td">
<input style="WIDTH: 127px" name=PolicyId >
<a href="javascript:void(0)" onclick="javascript:window.open
('zi.html','newwindow','toolbar=no,scrollbars=yes,resizable=no,top=200,left=300,width=400,height=380');"
><img src="../images/customerdetail.gif" /></a>
</td>
</tr>
</table>
</body>
</html>
子窗口 zi.html
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>子窗口</title>
<link href="../css/css.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/javascript">
function close()
{
window.opener='';
window.close();
}
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="bian">
<tr>
<td width="18%" class="titlebg bianr">人员编号</td>
</tr>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr><a href="fu.html?bdid=100100" onclick="close()">
<td width="18%" class="bgc_td_c"><font color=red>编号为100100的记录</font> </td>
</a>
</tr>
</table>
</body>
</html>
#2楼发布者:tznktg时间:2011-11-01 13:17:42
如果要返回到父窗口的 某个 设置了 ID 的 <div> 中 可以这样
在子窗口 onclick="close()" close() 之前加上 window.opener.document.getElementById('父窗体中某个 div 的 ID').innerHTML = document.getElementById('子窗体中某个 标签').value;
#3楼发布者:tznktg时间:2011-11-01 13:17:53
fu.html
HTML code<!----加个id---->
<input style="WIDTH: 127px" name=PolicyId id="PolicyId" >
zi.html
HTML code
<!-----以后标签写规范点,什么能嵌套,什么不能---->
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td width="18%" class="bgc_td_c"><a href="fu.html?bdid=100100"
onclick="window.opener.document.getElementById('PolicyId').value=this.innerHTML;self.close();" style="color:red"> 编号为
100100的记录 </a> </td>
</tr>
</table>
#4楼发布者:tznktg时间:2011-11-01 13:18:11
你把你记录内容前放个隐藏控件<input id="_hidBdid" type=hidden value="100100">
然后在父页面放一个接收该值的控件比如:<input type="text" id="ctrlid">
修改如下:
<script language=javascript>
function doPastValue(){
var pastvalue = document.getElementById("_hidBdid").value;
window.opener.document.getElementById('ctrlid').value = pastvalue;
window.close();
}
</script>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td width="18%" class="bgc_td_c">
<a href="javascript:doPastValue()" style="color:red"> 编号为100100的记录 </a>
</td>
</tr>
</table>