2009-11-26 40 views
0

我试图展现一个DIV并隐藏其他的div同一类,点击一个链接时如何使用jQuery的:不选择器

$(this).find('h2 a').click(function() { 
    $('.expand-collapse:eq(' + numberFix + ')').show('fast'); 
    $('.expand-collapse:eq:not(' + numberFix + ')').hide('fast'); 
return false; 
}); 

它确实表明受影响的股利,但其他divs不隐藏 - 我使用:不是以一种错误的方式?我用“n-child”这种方式使用它,并且工作得很好。

任何想法如何去这个将不胜感激! :)

回答

1

尝试:not(:eq(...))

$(this).find('h2 a').click(function() { 
    $('.expand-collapse:eq(' + numberFix + ')').show('fast'); 
    $('.expand-collapse:not(:eq(' + numberFix + '))').hide('fast'); 
    return false; 
}); 
+0

这在FF,但IE7似乎忽视了:没有选择器。 – timkl 2009-11-27 09:25:47

1

尝试兄弟姐妹:

$(this).find('h2 a').click(function(e) { 
    $('.expand-collapse:eq(' + numberFix + ')') 
     .show('fast').siblings().hide('fast'); 
    e.preventDefault(); 
});