在iframe父界面獲取iframe里面的標簽
上一篇里邊介紹了在里邊利用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獲取
實例:
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