使用 jQuery 定位 iFrame 一次

发布于 2024-08-26 08:08:44 字数 481 浏览 12 评论 0原文

我有一系列框架 (4),它们在页面中用于通过 Ajax 调用创建动态内容的加载。

在每个框架中,我都以父级元素为目标,并使用相应的内容更新它们,例如

$("#loadingGrid1",top.document).show();
$("#frameSkills",top.document).hide();

在 jQuery 中,有一种方法可以代替多次针对父页面上的特定元素,只需将页面一次定位到变量中,例如

var parentPage=$('#frameSkills',top.document);

然后使用它变量来应用像 $(parentPage > #loadingGrid1).hide() 这样的内容

希望我已经解释了我想要的内容。基本上,我必须在我制作的每个 jQuery 选择器中调用“top.document”,这似乎是浪费精力。

I have a series of frames (4) which are used in a page to create loading of dynamic content through Ajax calls.

In each of these frames I target parent level elements and update them with there respective content e.g.

$("#loadingGrid1",top.document).show();
$("#frameSkills",top.document).hide();

In jQuery is there a way to instead of targeting specific elements on the parent page multiple times, simply target the page once into a variable e.g.

var parentPage=$('#frameSkills',top.document);

And then use this variable to apply content like $(parentPage > #loadingGrid1).hide()

Hope I've explained what I'm after enough. Basically, I'm having to call "top.document" in every jQuery selector I make and it seems like a waste of energy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

疯到世界奔溃 2024-09-02 08:08:44

Jquery 对象可以像 DOM 节点一样用作上下文。

var parentPage = $('#frameSkills',top.document);
$("#myselector", parentPage).dostuff();

或者您可以使用 find 函数:

parentPage.find("#myselector").dostuff();

A Jquery object can be used as a context just like a DOM node.

var parentPage = $('#frameSkills',top.document);
$("#myselector", parentPage).dostuff();

Or you can use the find function:

parentPage.find("#myselector").dostuff();
永不分离 2024-09-02 08:08:44

这样的东西对我来说似乎最干净:

var page = $(top.document); //Define once
page.find("#loadingGrid1").show();
page.find("#frameSkills").hide();

当你调用 $(selector, context) 时,你(在所有情况下都是这样)在内部调用 context.find(selector)无论如何......也许还可以让您轻松地读/写/链接。

Something like this seems cleanest to me:

var page = $(top.document); //Define once
page.find("#loadingGrid1").show();
page.find("#frameSkills").hide();

When you call $(selector, context) you're (in all cases like this anyway) calling context.find(selector) inside anyway...might as well make it easy to read/write/chain as you go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文