大家看看我这个showModalDialog内select的值怎么返回给opener的select?

lauries 2004-07-15 10:24:49
我在body.htm上打开selUser.htm,现在想把selUser内的select所有的值返回给body.htm内的select,请问返回和怎么接收的函数怎么写?

====================================================
body.htm - 接收值的函数怎么写?

<html><head></head>
<script language="JavaScript">
function openwin(srcFile,obj,winFeatures)
{
window.showModalDialog(srcFile, obj, winFeatures);
}
</script>

<body>
<form action="" method="get" name="myForm">
<select name="selUser" size="4" multiple style="width:400px"></select>
<input type=button value=" 添加 " onclick="window.openwin('selUser.htm',myForm,'status:no;scrollbars:yes;help:no;dialogleft:400px;dialogtop:300px;dialogwidth:600px;dialogheight:400px')">
</form>
</body></html>

====================================================
selUser.htm - 传递值的函数怎么写?

<html><head></head>
<script language="JavaScript">
function AddUser()
{
//opener.addSel();
window.close();
}
</script>

<body>
<form action="" method="get" name="myForm">
<select name="selUser" size="3" multiple style="width:400px">
<option value="1">aaa</option>
<option value="2">bbb</option>
<option value="3">ccc</option>
</select>
<input name="button" type=button onclick="AddUser()" value=" 确认 ">
</form>
</body></html>

...全文
212 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
waiber 2004-07-15
  • 打赏
  • 举报
回复
弹出页面:

//此函数用于获取选中的值

function Select()
{
var IntcboLg=document.form1.selNode.length
var strcboValue=''
var strcboText=''
for (var i=0;i<IntcboLg;i++ )
{
if (strcboValue=='')
{
strcboValue=strcboValue+document.form1.selNode.options(i).value
strcboText=strcboText+document.form1.selNode.options(i).text
}else
{
strcboValue=strcboValue+','+document.form1.cboNode.options(i).value
strcboText=strcboText+','+document.form1.cboNode.options(i).text
}
}
if (strcboValue!=''){
var Strreturn=strcboValue+'#'+strcboText
window.returnValue=Strreturn
window.close();
}
}



接收页面:

function SelMutNode(url)
{

var strNode=showModalDialog(url',0,"dialogWidth:418px;dialogHeight:326px;status:no");
if (strNode!=-1 && typeof(strNode)!='undefined')
{
var strNodeary=strNode.split("#")
var strNodeID=strNodeary[0]
var strNodeName=strNodeary[1]
document.form1.txtNode.value=strNodeID;
document.form1.txtNode.value=strNodeName;
}

}


思路就是这样,自己去改改。
lauries 2004-07-15
  • 打赏
  • 举报
回复
谢,有启发作用

但是,我想把新开窗口selUser.htm内select的所有值全部转移到body.htm内的select中,两个select的值是一样的

这个问题我花了两三天的时间了,实在不会,寄托希望于此了
gamegod 2004-07-15
  • 打赏
  • 举报
回复
如果是想把第二页的东西增加到第一个页面,你看看我给你的代码,不知道是不是符合你的要求:
第一页:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>

<body>



<p><select size="8" name="txt">

<option>1</option>

</select></p>

<input type="button" onclick="window.open('in.htm')" value="Open">


</body>

</html>

第二页:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>

<script>
function CloseOpen() {

var ll=document.all.tags("input");

for(i=0;i<ll.length;i++)
{
if(ll[i].type=="checkbox")
{
if(ll[i].checked==true)
{
opener.document.all.txt.length=opener.document.all.txt.length+1;
opener.document.all.txt.options[opener.document.all.txt.length-1].text="123";
opener.document.all.txt.options[opener.document.all.txt.length-1].value=i;
}

}

}
window.close();
}
</script>
<body onunload="">
<p><input type="checkbox" name="C1" value="1">11</p>
<p><input type="checkbox" name="C1" value="2">21</p>
<p><input type="checkbox" name="C1" value="3">31</p>
<p><input type="checkbox" name="C1" value="4">41</p>
<p><input type="checkbox" name="C1" value="5">51</p>
<p><input type="checkbox" name="C1" value="6">61</p>
<p><input type="checkbox" name="C1" value="7">71</p>
<p><input type="button" onclick="javascript:CloseOpen();" value="close"></p>
</body>

</html>
lauries 2004-07-15
  • 打赏
  • 举报
回复
谢谢,谢谢大家,包括UP的“同志”,稍微整理了一下,代码是下面的:

body.htm

<html>
<head>
</head>
<script language="JavaScript">
function SelMutNode(url)
{
var obj=document.form1 ;
var strNode=showModalDialog(url,obj,"dialogWidth:418px;dialogHeight:326px;status:no");

var ret_val = strNode;
alert(ret_val)
if (ret_val!=null)
{
var strNodeary=ret_val.split("#");
var strNodeID=strNodeary[0];
var strNodeName=strNodeary[1]
//循环写值1,2,3 aaa,bbb,ccc
alert(strNodeID + " " + strNodeName);
a=strNodeID.split(",")
b=strNodeName.split(",")
for(i=0;i<a.length;i++)
document.form1.txtNode.options[document.form1.txtNode.options.length] = new Option(b[i],a[i])
}

}


//-->
</script>

<body>
<form action="" method="get" name="form1">
<select name="txtNode" size="4" multiple style="width:400px"></select>
<input type=button value=" add " onclick="SelMutNode('selUser.htm')">
<input type="hidden" value="" name="retval">
</form>
</body>
</html>

selUser.htm

<html>
<head>
</head>
<script language="JavaScript">
function Select()
{
var f = window.dialogArguments;
var IntcboLg=document.form1.selNode.length;
var strcboValue='';
var strcboText='';
for (var i=0;i<IntcboLg;i++ )
{
if (strcboValue=='')
{
strcboValue=strcboValue+document.form1.selNode.options(i).value;
strcboText=strcboText+document.form1.selNode.options(i).text;
}else
{
strcboValue=strcboValue+','+document.form1.selNode.options(i).value;
strcboText=strcboText+','+document.form1.selNode.options(i).text;
}
}
if (strcboValue!=''){
var Strreturn=strcboValue+'#'+strcboText;
f.retval.value=Strreturn;
window.returnValue=Strreturn
window.close();
}
}

</script>

<body>
<form action="" method="get" name="form1">
<select name="selNode" size="3" multiple style="width:400px">
<option value="1">aaa</option>
<option value="2">bbb</option>
<option value="3">ccc</option>
</select>
<input name="button" type=button onclick="Select()" value="¡¡Confirm¡¡">
</form>
</body>
</html>

希望此贴可以帮助到所有有这个需要的人
孟子E章 2004-07-15
  • 打赏
  • 举报
回复
大概yisi


<html>
<head>
</head>
<script language="JavaScript">
function SelMutNode(url)
{
var obj=document.form1 ;
var strNode=showModalDialog(url,obj,"dialogWidth:418px;dialogHeight:326px;status:no");

var ret_val = strNode;
alert(ret_val)
if (ret_val!=null)
{
var strNodeary=ret_val.split("#");
var strNodeID=strNodeary[0];
var strNodeName=strNodeary[1]
//循环写值1,2,3 aaa,bbb,ccc
alert(strNodeID + " " + strNodeName);
a=strNodeID.split(",")
b=strNodeName.split(",")
for(i=0;i<a.length-1;i++)
document.form1.txtNode.options[document.form1.txtNode.options.length] = new Option(b[i],a[i])
}

}


//-->
</script>

<body>
<form action="" method="get" name="form1">
<select name="txtNode" size="4" multiple style="width:400px"></select>
<input type=button value=" add " onclick="SelMutNode('selUser.htm')">
<input type="hidden" value="" name="retval">
</form>
</body>
</html>
lauries 2004-07-15
  • 打赏
  • 举报
回复
再次修改了下,能够得到值了,但是我又写不进去body.htm的select中


===============================
body.htm //alert显示我已经把值取过来了

<html>
<head>
</head>
<script language="JavaScript">
function SelMutNode(url)
{
var obj=document.form1 ;
var strNode=showModalDialog(url,obj,"dialogWidth:418px;dialogHeight:326px;status:no");

var ret_val = obj.retval.value;
if (ret_val!=-1 && typeof(ret_val)!='undefined')
{
var strNodeary=ret_val.split("#");
var strNodeID=strNodeary[0];
var strNodeName=strNodeary[1]
//循环写值1,2,3 aaa,bbb,ccc
alert(strNodeID + " " + strNodeName);
document.form1.txtNode.value=strNodeID;
document.form1.txtNode.value=strNodeName;
}

}


//-->
</script>

<body>
<form action="" method="get" name="form1">
<select name="txtNode" size="4" multiple style="width:400px"></select>
<input type=button value=" add " onclick="SelMutNode('selUser.htm')">
<input type="hidden" value="" name="retval">
</form>
</body>
</html>

===========================================================================

selUser.htm

<html>
<head>
</head>
<script language="JavaScript">
function Select()
{
var f = window.dialogArguments;
var IntcboLg=document.form1.selNode.length;
var strcboValue='';
var strcboText='';
for (var i=0;i<IntcboLg;i++ )
{
if (strcboValue=='')
{
strcboValue=strcboValue+document.form1.selNode.options(i).value;
strcboText=strcboText+document.form1.selNode.options(i).text;
}else
{
strcboValue=strcboValue+','+document.form1.selNode.options(i).value;
strcboText=strcboText+','+document.form1.selNode.options(i).text;
}
}
if (strcboValue!=''){
var Strreturn=strcboValue+'#'+strcboText;
f.retval.value=Strreturn;
window.returnValue=Strreturn
window.close();
}
}

</script>

<body>
<form action="" method="get" name="form1">
<select name="selNode" size="3" multiple style="width:400px">
<option value="1">aaa</option>
<option value="2">bbb</option>
<option value="3">ccc</option>
</select>
<input name="button" type=button onclick="Select()" value="¡¡Confirm¡¡">
</form>
</body>
</html>

上面代码显示已经取到值了,但是没有写入body.htm的select中,????
lauries 2004-07-15
  • 打赏
  • 举报
回复
net_lover(孟子E章) 老师:

我根据您提供的修改了部分脚本,可以提示不支持此对象
lauries 2004-07-15
  • 打赏
  • 举报
回复
net_lover(孟子E章) 老师:

您帮我改改这个文件,我花了几天时间了,实在是不知道了,只好求助于大家了!
我还没有学好这些!
孟子E章 2004-07-15
  • 打赏
  • 举报
回复
http://dev.csdn.net/develop/article/15/15113.shtm
孟子E章 2004-07-15
  • 打赏
  • 举报
回复
var strNode=showModalDialog(url,window,"dialogWidth:418px;dialogHeight:326px;status:no");



window.dialogArguments.document.form1.sel1.options[window.dialogArguments.document.form1.sel1.length] = new Option("txt","value",true,true)
window.returnValue=Strreturn
lauries 2004-07-15
  • 打赏
  • 举报
回复
测试没有成功,代码改写为一下:

====================================================
body.htm

<html><head></head>
<script language="JavaScript">
function SelMutNode(url)
{

var strNode=showModalDialog(url,0,"dialogWidth:418px;dialogHeight:326px;status:no");
if (strNode!=-1 && typeof(strNode)!='undefined')
{
var strNodeary=strNode.split("#")
var strNodeID=strNodeary[0]
var strNodeName=strNodeary[1]
document.form1.selNode.value=strNodeID;
document.form1.selNode.text=strNodeName;
}

}

//-->
</script>

<body>
<form action="" method="get" name="form1">
<select name="selNode" size="4" style="width:400px"></select>
<input type=button value=" add " onclick="SelMutNode('selUser.htm')">
</form>
</body></html>


====================================================
selUser.htm

<html><head></head>
<script language="JavaScript">
function Select()
{
var IntcboLg=document.form1.selNode.length
var strcboValue=''
var strcboText=''
for (var i=0;i<IntcboLg;i++ )
{
if (strcboValue=='')
{
strcboValue=strcboValue+','+document.form1.selNode.options(i).value
strcboText=strcboText+','+document.form1.selNode.options(i).text
}else
{
strcboValue=strcboValue+','+document.form1.selNode.options(i).value
strcboText=strcboText+','+document.form1.selNode.options(i).text
}
}
if (strcboValue!=''){
var Strreturn=strcboValue+'#'+strcboText
window.returnValue=Strreturn
window.close();
}
}

</script>

<body>
<form action="" method="get" name="form1">
<select name="selNode" size="3" multiple style="width:400px">
<option value="1">aaa</option>
<option value="2">bbb</option>
<option value="3">ccc</option>
</select>
<input name="button" type=button onclick="Select()" value="¡¡Confirm¡¡">
</form>
</body></html>

========================================
可是我测试结果,总是不能传递值?????
lauries 2004-07-15
  • 打赏
  • 举报
回复
测试ing

从此发现不大会javascript就玩完

28,409

社区成员

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

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