javascript实现打开窗体以及窗体间传值

父窗体js代码(打开子窗体):

ExpandedBlockStart.gif js_open
 1 " text/javascript ">
 2          // 打开模式对话框 取得返回值
 3          function OpenModalDialog() {
 4              // 用一个value来接受返回值
 5               var value = window.showModalDialog( " ModalDialogChild.aspx "" ModalDialog "" dialogWidth=800px; dialogHeight=1000px; center:Yes; Help:No; Resizable:No; Status:no; edge:sunken ");
 6             $( " #txtMsg ").val(value);
 7         }
 8 
 9          // 通过window.open打开窗体 取得返回值
10          function OpenWin() {
11             window.open( " winChild.aspx "" window "" height=800,width=1000,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,location=no,status=no ");
12         }
13     

父窗体页面html:

ExpandedBlockStart.gif html
 1 
 2     " form1 " runat= " server ">
 3     

 4         " button " id= " btn " value= " OpenModalDialog " οnclick= " OpenModalDialog(); " />
 5         
 6         
 7         ModalDialog:" txtMsg " runat= " server ">
 8         
 9         
10         " button " id= " Button1 " value= " OpenWin " οnclick= " OpenWin(); " />
11         
12         
13         OpenWin:" txtWinMsg " runat= " server ">
14     

15     
16 
子窗体_ 模式对话框:
ExpandedBlockStart.gif ModalDialog
 1 " server ">
 2     
 3     " text/javascript ">
 4         function GetValue() {
 5              // 通过window.returnValue来返回值到父窗体 由父窗体中定义的value接收
 6              window.returnValue = document.getElementById( " txtMsg ").value;
 7             window.close();
 8         }
 9     
10 
11 
12     " form1 " runat= " server ">
13     

14         " txtMsg " runat= " server " οnblur= " GetValue(); ">
15     

16     
17 
子窗体 _Window.Open页面:
ExpandedBlockStart.gif window.open
 1 " server ">
 2     
 3     " text/javascript ">
 4         function SetWinValue() {
 5              // window.opener为打开该页面的父页面引用 可以用过引用来获取父窗体的控件
 6              window.opener.document.getElementById( " txtWinMsg ").value = document.getElementById( " txtMsg ").value;
 7              // 下面语句为了防止关闭页面时 出现关闭提示
 8              window.opener =  null;
 9             window.open( ''' _self ''');
10              // 关闭
11              window.close(); 
12         }
13      
14 
15 
16     " form1 " runat= " server ">
17     

18         " text " id= " txtMsg " />
19         " button " id= " btn " value= " 给父窗体赋值 " οnclick= " SetWinValue(); " />
20     

21     
22 

 

转载于:https://www.cnblogs.com/holyknight-zld/archive/2012/10/30/openwin.html

你可能感兴趣的:(javascript实现打开窗体以及窗体间传值)