上一篇裏邊介紹了在裏邊利用iframe引入另外一個html導航文件,有興趣的朋友能夠看一看 http://www.cnblogs.com/simba-lkj/p/6031662.htmlhtml
目前遇到一些問題們,想要在引用了iframe的文件裏修改iframe裏邊的樣式。jquery
解決了這個問題,整理一下,供你們參考數組
demo:spa
<div class="iframe">htm
<iframe src="header.html" width="100%" height="442px" marginwidth="0" frameborder="no" scrolling="no"></iframe>blog
</div>rem
一、這是我首先考慮的一個方法get
獲取iframe引入的html文件元素經過id獲取iframe
實例:it
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中的元素
一、:var test = $("#iframe的ID").contents().find("#iframe中的控件ID");//jquery 方法1
var test2 = $("#iframe中的控件ID",document.frames("frame的name").document);//jquery 方法2