对JS不熟悉了,搞了一个多小时,郁闷。
关闭子页面,把子页面的姓名文本框的值赋值给父页面姓名文本框。
现在贴出代码,供大家学习及自己备用。
父页面名:ParentPage.aspx
JS脚本:
主要是使用open打开子窗体。
1
<
script type
=
"
text/javascript
"
>
2
3 // 打开子页面
4 function openChild()
5 {
6 window.open( ' ChildPage.aspx ' , ' 子窗体 ' , ' height=300 ' );
7 }
8 </ script >
2
3 // 打开子页面
4 function openChild()
5 {
6 window.open( ' ChildPage.aspx ' , ' 子窗体 ' , ' height=300 ' );
7 }
8 </ script >
HTML代码:
1
姓名
<
asp:TextBox ID
=
"
txtName
"
runat
=
"
server
"
></
asp:TextBox
>
2 < br />
3 年龄 < asp:TextBox ID = " txtAge " runat = " server " ></ asp:TextBox >
4 < asp:Button ID = " btnSelect " runat = " server " Text = " 请选择 " OnClientClick = " openChild() ; " />
5 < br />
6 性别 < asp:DropDownList ID = " ddlSex " runat = " server " >
7 < asp:ListItem Text = " 男 " Selected = " True " ></ asp:ListItem >
8 < asp:ListItem Text = " 女 " ></ asp:ListItem >
9 </ asp:DropDownList >
2 < br />
3 年龄 < asp:TextBox ID = " txtAge " runat = " server " ></ asp:TextBox >
4 < asp:Button ID = " btnSelect " runat = " server " Text = " 请选择 " OnClientClick = " openChild() ; " />
5 < br />
6 性别 < asp:DropDownList ID = " ddlSex " runat = " server " >
7 < asp:ListItem Text = " 男 " Selected = " True " ></ asp:ListItem >
8 < asp:ListItem Text = " 女 " ></ asp:ListItem >
9 </ asp:DropDownList >
子页面名:ChildPage.aspx
JS脚本:
1
<
script type
=
"
text/javascript
"
>
2 // 父页面获取子页面的值
3 function getChildText()
4 {
5 window.opener.document.getElementById( ' txtName ' ).value = document.getElementById( ' txtC hildName ' ).value;
2 // 父页面获取子页面的值
3 function getChildText()
4 {
5 window.opener.document.getElementById( ' txtName ' ).value = document.getElementById( ' txtC hildName ' ).value;
6 window.close();
7 }
8</script>
HTML代码:
1
姓名
<
asp:TextBox
ID
="txtChildName"
runat
="server"
></
asp:TextBox
>
2 < br />
4 < asp:Button ID ="btnClose" runat ="server" Text ="关闭刷新父窗体" OnClientClick ="getChildText()"/ >
2 < br />
4 < asp:Button ID ="btnClose" runat ="server" Text ="关闭刷新父窗体" OnClientClick ="getChildText()"/ >