使用 jQuery 定位 iFrame 一次
我有一系列框架 (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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Jquery 对象可以像 DOM 节点一样用作上下文。
或者您可以使用
find
函数:A Jquery object can be used as a context just like a DOM node.
Or you can use the
find
function:委托怎么样?
What about Delegates?
这样的东西对我来说似乎最干净:
当你调用
$(selector, context)
时,你(在所有情况下都是这样)在内部调用context.find(selector)
无论如何......也许还可以让您轻松地读/写/链接。Something like this seems cleanest to me:
When you call
$(selector, context)
you're (in all cases like this anyway) callingcontext.find(selector)
inside anyway...might as well make it easy to read/write/chain as you go.