网站制作学习网JS脚本→正文:jQuery操作Frame(iframe)网页框架
字体:

jQuery操作Frame(iframe)网页框架

JS脚本 2010/8/30 18:53:00  点击:不统计

原载于:转www.载for网站制作学习asp必.cn究
jQuery操作Frame(iframe)网页框架,对左右网页框架,上下网页框架的jqery操作进行的详细的解释
1.在父窗口中操作 选中IFRAME中的所有单选钮
$(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");

2.在IFRAME中操作 选中父窗口中的所有单选钮
$(window.parent.document).find("input[@type='radio']").attr("checked","true");
iframe框架的:<iframe src="test.html" id="iframe1" width="700" height="300" frameborder="0" scrolling="auto"></iframe>
IE7中测试通过 回去你自己试试吧
刚才google到的,补充一下
I beat my head against this wall for quite some time.

Try this:
$("#myid", top.document);
the top.document tells the selector to target the myid element which
exists in the topmost document (your parent page). In order for this
to work, jquery must be loaded in the file which is viewed through the
iframe.

我的代码
$('#parentElem', top.document).append('<div class="imgbox" id="imgbox"><img class="img" src="pp.png" id="img"></div>');

upc不是说了么
1.在父窗口中操作 选中IFRAME中的所有单选钮
$(window.frames["iframe1"].document).find("input[@type='radio']").attr("checked","true");

那选择id自然就是依然使用find方法
$(window.frames["iframe1"].document).find("#id")

实际楼上上的方法本质上在Jq内部也是调用了find方法
父窗体调用IFrame中的方法(right)为ifram的id
document.frames["right"].expand();
父窗体:parent;

子窗体:opener;(window.opener.reload();)

上面的都是网上摘的,下面补充很重要的一点:

你可能已经注意到了,上面提及的都是自上而下的selector方法,也就是从上级window查找下级window(包括iframe创建的window),如果我们希望从下级window,比如希望通过iframe中的window找到iframe的parentNode,可以这样:

var parentFrame=null;
if(window!=window.top){parentFrame=window.frameElement.name};

往下就可以直接$(.....

当然,一个topwindow中仅仅包含一个iframe时我们没有必要这样,但当若干iframe存在时,这个方法还是很有用的。

在此注意一下:一定要在$(function(){});中进行操作,我就犯错了,弄了半天,一直出于undefind,后来才找出来的。

转载于:http://hi.baidu.com/51plan/blog/item/381ee57e4c328e3f0cd7daac.html


<网f站o学a习s制p作.cn>

·上一篇:jquery对象筛选 >>    ·下一篇:jquery对象筛选 >>
推荐文章
最新文章