使用jQuery在Frame中获取元素 [英] Getting element within Frame using jQuery

查看:143
本文介绍了使用jQuery在Frame中获取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问框架内的一个元素,但到目前为止还没有运气.我在这里已经阅读了很多关于stackoverflow和jQuery文档的示例,但是我看到的所有示例都是针对iFrame的,这些iFrame的行为与传统框架不同.我的页面结构如下所示,删除了实际内容:

I am trying to access an element which is inside of a frame but haven't had any luck getting to it so far. I have read through a lot of examples here on stackoverflow and in jQuery's documentation but all the examples I've seen have been in reference to iFrames which behave differently than traditional frames. My page structure is as shown below with actual contents removed:

<html>
<head></head>
<frameset>
<frame name="Menu"><html><body>
    <!--Menu contents-->
</body></html></frame>

<frameset>
<frame name="SettingsTree"><html><body>
    <!--Setting options-->
</body></html></frame>
<frame name="SettingsGrid" id="SettingsGrid"><html><body>
    <div id="findthis"></div>
    <!--Setting grid values-->
</body></html></frame>
</frameset>

</frameset>
</html>

在iFrame中获取"findthis"内容的方法是

The way to get contents of "findthis" within an iFrame would be

$('#SettingsGrid').contents().find('#findthis')

但是这不会返回任何东西. $('#SettingsGrid')对象的长度为1,并且我希望它具有所有的html.但是,当我在该对象上调用.contents()时,它什么也不返回.我不知道这是否是因为尚未正确将其加载到DOM中,还是存在其他问题.

however this doesn't return anything. The $('#SettingsGrid') object exists with a length of 1 and all of the html I would expect it to have. However when I call .contents() on that object it returns nothing. I don't know if this is because it hasn't been properly loaded into the DOM or if there is some other issue.

推荐答案

尝试一下:

$('#findthis', window.parent.frames[0].document)

或从顶层:

$('#findthis', top.window.frames[0].document)

请参阅上一个问题/答案:在另一个上下文中运行JQuery框架

See previous question/answer: Run JQuery in the context of another frame

这篇关于使用jQuery在Frame中获取元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆