关于子窗口与父窗口传送数据的问题

yaozheng 2004-04-02 12:46:27
很多论坛都有这样一个功能,就是可以插入表情图片,一般都是先用window.open弹出一个子窗口,然后在子窗口内点击图片,就可以在父窗口的文本框内显示相关信息。

其他的页面我已全部做好了,但是问题是我在子窗口点击图片后,并没有在父窗口相应的文本框内增加任何信息,不知何故。

这是我在子窗口内要添加到父窗口的代码,请问有错误吗?f1是父窗口的表单名,content是表单里一个文本框名,请问是应该用self.opener吗?

function emotions(emotions)
{
self.opener.document.f1.content.value+=emotions
}
...全文
76 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
19az 2004-09-09
  • 打赏
  • 举报
回复
谢谢各位的代码,帮我解决了大问题!
yaozheng 2004-04-02
  • 打赏
  • 举报
回复
楼上,我去掉self问题依旧!
baby21st 2004-04-02
  • 打赏
  • 举报
回复
try

function emotions(emotions)
{
opener.document.f1.content.value += emotions ;
}
cjf1009 2004-04-02
  • 打赏
  • 举报
回复
mark
yaozheng 2004-04-02
  • 打赏
  • 举报
回复
靠,问题解决了,原来和代码没有关系,都是ie惹的祸,具体也不解释了,谢谢回复我的朋友!!!
zjwz001 2004-04-02
  • 打赏
  • 举报
回复

parent.document.f1.content.value+=emotions
yaozheng 2004-04-02
  • 打赏
  • 举报
回复
我把代码都发上来,请高手指教!!共两个文件,图片略,不影响调试,请帮我看看究竟是哪里出问题了!!

父窗口的代码:文件名随便取
<HTML><HEAD><TITLE></TITLE>
<BODY>
<FORM action=save.asp method=post name=f1>
<DIV align=center>
<TABLE border=1 borderColorDark=#ffffff borderColorLight=#c0c0c0 cellPadding=0
cellSpacing=0
width=755>
<TBODY>
<TR>
<TD align=right bgColor=#ff6600 height=25 vAlign=center
width=754><P align=center><STRONG><FONT color=#ffffff size=3>添 加 主
题</FONT></STRONG></P></TD></CENTER></TR>
<CENTER>
<TR>

<TD bgColor=#ffffff height=30 vAlign=center width=626>
<p align="center"> <FONT
color=#ff0000><B> 选择表情(鼠标单击): </B></FONT>
<script>
function windowopen(loadpos)
{window.open(loadpos,"subwin","resizable,scrollbars,status,width=400 height=300");}
</script>
<a href=javascript:windowopen('emotions.htm')><b>更多表情图片</b></a><FONT
color=#ff0000><B><BR>  </B></FONT>
<BR>
<TEXTAREA cols=77 name=content rows=15></TEXTAREA><INPUT type=submit value=发表主题>  <INPUT name=B2 type=reset value=重新填写></p>
</TD></TR>
</TBODY></TABLE></DIV></FORM>
</BODY></HTML>



子窗口的代码:emotions.htm
<html>
<head>
<title>编程爱好者论坛 — 表情图片库</title>
<link rel=stylesheet href=style.css></head>
<script>
function emotions(smile)
{
self.opener.document.f1.content.value+=smile;
}
</script>
<body>
<p align="center"><b><font color="#FF0000">

请单击选择表情图片</font></b>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<script>
for(i=1;i<=80;i=i+1) {
document.write("<td width=10% height=25><img border=0 src=emotions/"+i+".gif onclick=javascript:emotions('[em"+i+"]') onmouseover=this.style.cursor='hand'></td>")
if (i%10==0){document.write("</tr><tr>");}
}
</script>

</tr></table>
<form method="POST" name="f1">
<p align="center"><input type="text" name="content" size="20"></p>
</form>
</body></html>

yaozheng 2004-04-02
  • 打赏
  • 举报
回复
快沉下去了,我顶!!!
yaozheng 2004-04-02
  • 打赏
  • 举报
回复
这是子窗口的代码,父窗口就不用写了吧。我在父窗口是用window.open调用的,至于父窗口中的表单名和文本框名肯定没写错。

<html><head><title></title></head>
<script>
function emotions(emotions)
{
self.opener.document.f1.content.value+=emotions; //去不去掉self都一样
}
</script>
<body>
<p align="center"><b><font color="#FF0000">

请单击选择表情图片</font></b>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<script>
//以下是显示表情图片的代码
for(i=1;i<=80;i=i+1) {
document.write("<td width=10% height=25><img border=0 src=emotions/"+i+".gif onclick=javascript:emotions('[em"+i+"]') onmouseover=this.style.cursor='hand'></td>")
if (i%10==0){document.write("</tr><tr>");}
}
</script>
</tr></table>
</body></html>
xijupony 2004-04-02
  • 打赏
  • 举报
回复
在子窗体操作父窗体不是用opener,而是window.parent呀
cxty 2004-04-02
  • 打赏
  • 举报
回复
拿代码给大家小看看!就知道了!
yaozheng 2004-04-02
  • 打赏
  • 举报
回复
另外想问一下,是不是我打开子窗口的方式不对阿,我就是用window.open方式打开的阿,应该不会有问题吧!!
yaozheng 2004-04-02
  • 打赏
  • 举报
回复
都是正确的,代码也都检查过了,我刚刚在子窗口内加了一个文本框,

表单名也取f1,文本框名也取content,然后把代码中opener去掉都能通过,

但是如果想传到父窗口中就是不行,百思不得其解。


是不是因为我是直接打开html文件的关系,而不是用http方式打开?
pizixt 2004-04-02
  • 打赏
  • 举报
回复
window.opener.document.f1.content.value+=emotions;
pyonline 2004-04-02
  • 打赏
  • 举报
回复
function emotions(emotions)
{
opener.window.document.f1.content.value += emotions ;
}
cxty 2004-04-02
  • 打赏
  • 举报
回复
看一下
function emotions(emotions)
{
alert(emotions);
alert(opener.document.f1.content.value);
}

出来的值是什么~~~~

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧