磁带价格:关于子窗体向父窗体传值方法

来源:百度文库 编辑:偶看新闻 时间:2024/05/05 08:33:01

第一种:Open

  1. 通过Opener方法调用父窗体方法传值

  父窗体

 1
 2
 3
 4父窗体
 5
 6
 7
 8
 9
10
11 
12     function openWindow() {
13        window.open(子窗体.html','newWindow','height=300,width=300,scrollbars=auto');       
14     } 
15     function setValue(returnValue) {
16          document.getElementById('txtvalue').value=  returnValue;
17     }
18 
19
20
21 

  子窗体

 1
 2
 3
 4子窗口
 5  
 6
 7       function valueExit() {
 8           var returnValue =  docment.getElementById('txtValue').value;
 9           opener.setValue(returnValue);                  
10           window.close();
11       }
12  
13
14
15子窗口!



16
17
18
19 
20
21

22
23

2.在子窗体里面用window.opener.document.from方法传值

  父窗体

 1
 2
 3
 4父窗体
 5
 6
 7
 8
 9
10
11 
12 
20 
21
22
23 

  Code

 1
 2
 3
 4子窗口
 5
 6
 7 子窗口!

 8
 9
10
11tt.value;self.close();' />
12
13

14
15

扩展:子窗体关闭要刷新父窗体,在子窗体赋值的第一句加上opener.location= opener.location.href;

  第二种:ShowModalDialog

  1.window.returnValue方法传值

  父窗体

 1
 2
 3 
        function fnOpen() {
 4    var returnTarget = window.showModalDialog("zichuangti.aspx", 'newWindow', 'dialogHeight=500px;dialogWidth=700px;center=yes;resizable=yes;help=no;');
 5             if (returnTarget != undefined && returnTarget.length > 0) {
 6                   document.getElementById("oArgs").value=returnTarget;
 7             }
        }
 8 
 9
10
11    
12        


13            传过来的值: 
14            
15        

16    
17
18
19
20
21
22



     
    function exit() 
    {
        window.returnValue = form1.txtreturn.value; //返回值
         window.close();
    }
    


    
        


            传递过来的值: 
            
        

    


  扩展:子窗体关闭要刷新父窗体,在打开窗体的URL后面加上 window.location.reload();

本文作者:未知