• 全部
  • .NET Framework
  • ASP
  • Web Services
  • .NET互联网桌面应用
  • VB
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • AppLauncher
  • 问答

javascript如何做弹出窗口并返回值~~~急,在线等待!

forever102 2009-03-31 12:31:51
我想做一个像浏览似的按钮,点击按钮弹出一窗口,然后点击弹出窗口里面的摸个值后,窗口自动关闭,并将值传回到父窗口!
请大侠吗帮帮忙,都弄了一天了就是做不出来!
谢谢!!
...全文
816 点赞 收藏 14
写回复
14 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
angleoldhen 2009-05-23
用层怎么做啊。给个例子嘛,让我这些新手少走弯路
回复
forever102 2009-03-31
现在窗口用String sUrl = "DetailClient.aspx?client=" + Client.Text;
String sFeatures = "'height=320;width=160;left=100;top=50;location=no;menubar=no;resizable=yes;scrollbars=no;status=no;titlebar=yes;toolbar=no'";
String sScript = "";
sScript += "<script language=javascript>";
sScript += "window.open('" + sUrl + "',''," + sFeatures + ");";
sScript += "</script>";
Response.Write(sScript);
也能打开,就是不知道如何返回值并同时关闭打开的窗口!
回复
forever102 2009-03-31
Response.Write("<script language=javascript>parent.document.getElementById("client").value="+client+"; window.close();</script>");
1楼的大哥在后台这样写怎么有错误啊?
回复
水寒冰 2009-03-31
可以把弹出的窗口换成弹出一个层,这样取值就方便多了,而且不会被浏览器阻止
回复
copico 2009-03-31
用JS脚本可以从子窗口控制父窗口的某个控件,来改变值。


子窗口按钮调用的JS代码.

function updateStr(str)
{
parent.document.getElementById("hid_textBox").value = str;
window.close();
}


父窗口的hid_textBox控件的值就会改变
回复
yh7272hy 2009-03-31
用层做,取值方便,弹出窗口也很漂亮,容易控制
回复
major 2009-03-31
一回事撒把child.aspx.cs中的Response.Write("<script>window.opener.document.getElementById(\"tbParent\").value='" + tbChild.Text + "'</script>");
改成
Response.Write("<script>window.opener.document.getElementById(\"txt\").value='" + tbChild.Text + "'</script>");
就可以了。

回复
forever102 2009-03-31
显示返回值的文本框 <INPUT id="txt" type="text" runat="server">中如果是<asp:textBox>该如何写呢?
回复
forever102 2009-03-31
真是太谢谢你了!
用asp.net标签就不行吗、?
回复
major 2009-03-31
我给你做了一个例子,你自己看看一下,有看不明白的给我发消息。
下载地址:http://800.himay.com/ContentPane.aspx?down=ok&filepath=wbxf2008%2fWebSite7.rar
回复
csshan 2009-03-31
弹出窗口将参数值回传到父窗口
方法1:window.open
father webform
按钮<asp:button id="Button2" runat="server" Text="Button"></asp:button>
显示返回值的文本框<INPUT id="txt" type="text" runat="server">,这里一定要是htmlcontrol,如果是webcontrol是得不到返回值的。

private void Button2_Click(object sender, System.EventArgs e)
{
Response.Write("<script>window.open('son.aspx')</script>");
}

son webform
<INPUT id="ipload" runat="server" style="Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 64px"
type="file">上传文件的控件
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 136px" runat="server" Text="Button"></asp:Button>
button事件里面的内容是:
Response.Write("<script>window.opener.document.all['txt'].value='"+ipload.PostedFile.FileName.ToString()+"';</script>");
Response.Write("<script>window.opener.forms[0].submit();</script>");
Response.Write("<script>window.close();</script>");

方法2 window.showModalDialog()
父窗口
<asp:button id="Button1" style="Z-INDEX: 101; LEFT: 216px; POSITION: absolute; TOP: 72px" runat="server"
Text="Button"></asp:button><asp:label id="Label1" style="Z-INDEX: 102; LEFT: 304px; POSITION: absolute; TOP: 184px" runat="server">Label</asp:label>
<DIV id="lab" style="DISPLAY: inline; Z-INDEX: 103; LEFT: 368px; WIDTH: 208px; POSITION: absolute; TOP: 32px; HEIGHT: 67px"
runat="server" ms_positioning="FlowLayout"></DIV>
<INPUT id="txt" style="Z-INDEX: 104; LEFT: 160px; POSITION: absolute; TOP: 128px" type="text"
runat="server">
<script language="javascript">
function openmode()
{
var returnValue=window.showModalDialog("popup.aspx");
document.Form1.TextBox1.value=returnValue;

}
</script>
<asp:TextBox id="TextBox1" style="Z-INDEX: 105; LEFT: 168px; POSITION: absolute; TOP: 224px"
runat="server"></asp:TextBox>

code behind那边
private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add("onclick","openmode()");
}
子页面
this.Label1.Text=upload.PostedFile.FileName.ToString();
string [] tmp=this.Label1.Text.ToString().Split('\\');
string temp="";
for(int i=0;i<tmp.Length;i++)
{
temp=temp+tmp[i]+"\\\\";
}
temp=temp.Substring(0,temp.Length-2);

this.TextBox1.Text=temp;
Response.Write("<script>window.returnValue='"+temp+"';</script>");
// Response.Write("<script>window.close();</script>");


回复
csshan 2009-03-31
弹出窗口将参数值回传到父窗口
方法1:window.open
father webform
按钮<asp:button id="Button2" runat="server" Text="Button"></asp:button>
显示返回值的文本框<INPUT id="txt" type="text" runat="server">,这里一定要是htmlcontrol,如果是webcontrol是得不到返回值的。

private void Button2_Click(object sender, System.EventArgs e)
{
Response.Write("<script>window.open('son.aspx')</script>");
}

son webform
<INPUT id="ipload" runat="server" style="Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 64px"
type="file">上传文件的控件
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 136px" runat="server" Text="Button"></asp:Button>
button事件里面的内容是:
Response.Write("<script>window.opener.document.all['txt'].value='"+ipload.PostedFile.FileName.ToString()+"';</script>");
Response.Write("<script>window.opener.forms[0].submit();</script>");
Response.Write("<script>window.close();</script>");

方法2 window.showModalDialog()
父窗口
<asp:button id="Button1" style="Z-INDEX: 101; LEFT: 216px; POSITION: absolute; TOP: 72px" runat="server"
Text="Button"></asp:button><asp:label id="Label1" style="Z-INDEX: 102; LEFT: 304px; POSITION: absolute; TOP: 184px" runat="server">Label</asp:label>
<DIV id="lab" style="DISPLAY: inline; Z-INDEX: 103; LEFT: 368px; WIDTH: 208px; POSITION: absolute; TOP: 32px; HEIGHT: 67px"
runat="server" ms_positioning="FlowLayout"></DIV>
<INPUT id="txt" style="Z-INDEX: 104; LEFT: 160px; POSITION: absolute; TOP: 128px" type="text"
runat="server">
<script language="javascript">
function openmode()
{
var returnValue=window.showModalDialog("popup.aspx");
document.Form1.TextBox1.value=returnValue;

}
</script>
<asp:TextBox id="TextBox1" style="Z-INDEX: 105; LEFT: 168px; POSITION: absolute; TOP: 224px"
runat="server"></asp:TextBox>

code behind那边
private void Page_Load(object sender, System.EventArgs e)
{
Button1.Attributes.Add("onclick","openmode()");
}
子页面
this.Label1.Text=upload.PostedFile.FileName.ToString();
string [] tmp=this.Label1.Text.ToString().Split('\\');
string temp="";
for(int i=0;i<tmp.Length;i++)
{
temp=temp+tmp[i]+"\\\\";
}
temp=temp.Substring(0,temp.Length-2);

this.TextBox1.Text=temp;
Response.Write("<script>window.returnValue='"+temp+"';</script>");
// Response.Write("<script>window.close();</script>");


回复
forever102 2009-03-31
Response.Write(" <script language=javascript>parent.document.getElementById("client").value="+client+"; window.close(); </script>");
1楼的大哥在后台这样写怎么有错误啊?
回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2009-03-31 12:31
社区公告
暂无公告