0

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

在这些框架中的每一个中,我都针对父级元素并使用相应的内容更新它们,例如

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

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

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

然后使用这个变量来应用内容,比如$(parentPage > #loadingGrid1).hide()

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

4

3 回答 3

0

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();
于 2010-03-19T14:56:03.040 回答
0

这样的事情对我来说似乎最干净:

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

当你打电话时$(selector, context),你(无论如何都是这样)context.find(selector)在里面打电话……也可以让你随时随地轻松读/写/链接。

于 2010-03-20T12:41:44.533 回答
0

代表们呢

于 2010-03-19T14:56:33.107 回答