<div class="foo">
<img src="loading.gif" class="loading" style="display: none;" />
</div>
JS:
$("div[class='foo']").click(function(e) {
e.preventDefault();
$(this).hide();
$(/* somehow select the loading img of exactly this div with class foo (not others) */).show();
});
哇!您可以将上下文传递给$选择器!尼斯。 – randomguy 2010-08-11 13:37:19
@randomguy:选择器上下文映射到* find()*方法,因此'$('img.loading',this)'与$(this).find('img.loading')'相同。我认为,选择器上下文更“更好”。 – 2010-08-11 13:41:03