上一篇里边介绍了在里边利用iframe引入另一个html导航文件,有兴趣的朋友可以看一看 http://www.cnblogs.com/simba-lkj/p/6031662.html

目前遇到一些问题们,想要在引用了iframe的文件里修改iframe里边的样式。

解决了这个问题,整理一下,供大家参考

demo:

<div class="iframe">

<iframe src="header.html" width="100%" height="442px" marginwidth="0" frameborder="no" scrolling="no"></iframe>

</div>

1、这是我首先考虑的一个方法

获取iframe引入的html文件元素通过id获取

要在网页加载完之后再进行这段代码 
window.onload = function(){
 var test = document.getElementById('iframe的id').contentWindow.document.getElementById('iframe里要获取的元素的id');
 console.log(test);
 test.style.display = "none";
}
 
2、可以在iframe文件js里获取父网页的相对路径,将相对路径存储在一个数组中,通过判断相对路径 来进行操作

实例:

var URL  = window.parent.location.pathname;

路径数组:

var arrURL = ["/CASE/aishuoke/index.html","/CASE/aishuoke/about.html","/CASE/aishuoke/news.html","/CASE/aishuoke/download.html","/CASE/aishuoke/case.html","/CASE/aishuoke/job.html","/CASE/aishuoke/shownews.html",

"/CASE/aishuoke/showinfo.html","/CASE/aishuoke/showimg_first.html","/CASE/aishuoke/showimg_second.html","/CASE/aishuoke/showimg_third.html","/CASE/aishuoke/showimg_forth.html"];

switch (URL){

case arrURL[0]:

$("#shouye").addClass("show").siblings().removeClass("show");

break;

}

 
总结:

在iframe中获取父窗口的元素

$('#父窗口中的元素ID', parent.document).click();jquery

在父窗口中获取iframe中的元素 

1、:var test = $("#iframe的ID").contents().find("#iframe中的控件ID");//jquery 方法1

  var test2 =  $("#iframe中的控件ID",document.frames("frame的name").document);//jquery 方法2

  var test3 = document.getElementById('iframe的id').contentWindow.document.getElementById('iframe里要获取的元素的id');//js方法
 
 转载请注明出处,谢谢合作*-* http://www.cnblogs.com/simba-lkj/p/6032458.html
 

最新文章

  1. HDOJ 1051. Wooden Sticks 贪心 结构体排序
  2. supervisor监管进程max file descriptor配置不生效的问题
  3. C#中 反射中的Assembly(装载程序集):
  4. Atitit prj 项目管理与行政管理(1)------项目环境的概览与建立
  5. window.onload()和$(function(){});的区别
  6. MySQL完整性语言
  7. 英语学习APP—百词斩
  8. Win7系统下利用U盘安装Ubuntu14.04麒麟版
  9. 新手!SDK Manager里找不到API安装的选项怎么办?
  10. 通过Workbook类 生成Excel导出数据
  11. Window 下安装Redis
  12. 14.9.2 Specifying the Row Format for a Table 指定 表的行格式
  13. SqlDataReader中的GetSqlValue()方法
  14. Oracle 12C 新特性之表分区或子分区的在线迁移
  15. [Luogu1801] 黑匣子 - Treap
  16. Linux netfilter 学习笔记
  17. logback 按时间和大小生成日志不生效的问题
  18. shell练习题1
  19. [剑指Offer]29-顺时针打印矩阵-Java
  20. spring boot -thymeleaf-异常处理

热门文章

  1. C#语法糖,让编程更具乐趣
  2. VS2010 MFC实现启动画面
  3. Bitnami Redmine插件记录
  4. USB驱动开发大全【转】
  5. ubuntu执行sudo apt-get update提示缺少公钥
  6. hadoop 安装教程 转载
  7. 【前端】Node.js学习笔记
  8. javaScript 将json字符串转换为json对象的方法解析
  9. 中文 iOS/Mac 开发博客列表(转)
  10. linux文件系统,文件的分类