码迷,mamicode.com
首页 > 其他好文 > 详细

iframe中 父页面和子页面查找元素的方法

时间:2014-11-21 17:52:14      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:ar   sp   on   div   art   bs   as   tt   nbsp   

从父页面中查找iframe子页面中对象的方法:
JS:

  1. document.getElementById(‘iframe‘).contentWindow //查找iframe加载的页面的window对象  
  2. document.getElementById(‘iframe‘).contentWindow.document //查找iframe加载的页面的document对象  
  3. document.getElementById(‘iframe‘).contentWindow.document.body //查找iframe加载的页面的body对象  
  4. document.getElementById(‘iframe‘).contentWindow.document.getElementById(‘icontent‘) //查找iframe加载的页面的id为icontent的对象  

jQuery:

  1. $(‘#iframe‘).contents() //查找iframe加载的页面的document对象  
  2. $(‘#iframe‘).contents().find(‘body‘) //查找iframe加载的页面的body对象  
  3. $(‘#iframe‘).contents().find(‘body‘).find(‘#icontent‘) //查找iframe加载的页面的id为icontent的对象  

从iframe子页面中查找父页面中对象的方法:
JS: 

  1. [window.]parent //查找父页面的window对象  
  2. [window.]parent.document //查找父页面的document对象  
  3. [window.]parent.document.body //查找父页面的body对象  
  4. [window.]parent.document.getElementById(‘button‘) //查找父页面中id为button的对象  

jQuery:

  1. $([window.]parent) //查找父页面的window对象  
  2. $([window.]parent.document) //查找父页面的document对象  
  3. $([window.]parent.document.body) //查找父页面的body对象  
  4. $([window.]parent.document.body).find(‘#button‘) //查找父页面中id为button的对象  

 

注:[window.] 代表可加可不加。

iframe中 父页面和子页面查找元素的方法

标签:ar   sp   on   div   art   bs   as   tt   nbsp   

原文地址:http://www.cnblogs.com/dengshaojun/p/4113068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!