JavaScript中父子页面数据交互实例详解

作者:简简单单 2013-06-08

js中关于父子页面数据交互一些写法

1.window.frames["test"].document.getElementById(‘menu’);
2.//由于所有的函数都存放在window对象里面,可去掉开头的window:
3.frames["test"].document.getElementById(‘menu’);
4.//在浏览器中,帧的name属性被默认等同于子页面的window对象,因此可以进一步简写:
5.test.document.getElementById(‘menu’);
window.frames["test"].document.getElementById('menu');
//由于所有的函数都存放在window对象里面,可去掉开头的window:
frames["test"].document.getElementById('menu');
//在浏览器中,帧的name属性被默认等同于子页面的window对象,因此可以进一步简写:
test.document.getElementById('menu');2.2 父页面访问子页面函数或对象。子页面的函数和对象都在其window对象里,同上,关键是获取该对象。

Java代码

1.//假如child.html定义了showMesg函数,需要在父中调用,则这样写
2.window.frames['test'].showMesg();
3.//简写形式
4.test.showMesg();
5.//同理,对象也是如此访问
6.alert(test.person);
//假如child.html定义了showMesg函数,需要在父中调用,则这样写
window.frames['test'].showMesg();
//简写形式
test.showMesg();
//同理,对象也是如此访问
alert(test.person);

例子

父窗口:a1.html

 代码如下 复制代码



 
    a.html
 
    words" content="keyword1,keyword2,keyword3">
   
   
 
 
 
 
   


          客户id:

     客户名称
   
     


 

子窗口:a2.html

 代码如下 复制代码



 
    a2.html
   
   
   
 
  
 
     


        
          
   
   
        
   
   
          
   
   
        
   
          
   
   
        
     
操作客户id客户名称
001深圳华为
002用友软件

 
 
 
 

相关文章

精彩推荐