使用JS或JQuery父页和Iframe子页之间互相读取元素

在网站后台界面的搭建中经常会用到Iframe的框架来进行菜单和内容部分的区分,但菜单要根据内容做出一定的变化就比在同页面判断麻烦一些

下面是一些在框架中可能会用到的一些获取元素的方法,根据实际情况进行修改应用

 

父页面获取Iframe子页的元素

JS版:document.getElementById("IframeID").contentWindow.document.getElementById("divID")
JQ版1:$("#divID",$("#iframeID")[0].contentWindow.document)
JQ版2:$("#iframeID").contents().find("#divID")

 

Iframe页获取父页面的元素
JS版:parent.document.getElementById("myDiv")
JQ版1:$("#divID",parent.document)
JQ版2:$(parent.document).find("#divID")

frameSet中,leftFrame获取mainFrame中的元素
JS版:parent.mainFrame.document.getElementById("divID")
JQ版:$("#divID",parent.mainFrame.document)

------------------------------ 分割线 ----------------------------

隐藏Iframe在IE6下出现的横向滚动条
在src页的head标签内加入
<style type="text/css">
html { overflow-x:hidden; }
</style>

 

 

原文链接:http://www.s-un.cn/Code/Javascript-and-JQuery-function-for-Iframe-page.html

posted @ 2015-12-07 17:43  半前端半设计的四不像  阅读(180)  评论(0)    收藏  举报