不要使用 id 并依赖选择器。而是使用类:
$SD = $('.SiteDescription'); // cache jquery object
$SD.on('click',function(){
// fade out all with this class
$SD.stop().animate({opacity:0},500);
// fade in new active element
$(this).stop().animate({opacity:1},500);
});
如果您尝试选择除该 id 之外的任何内容,您将选择页面上不是它的每个元素。我不认为那是你想要的。
不要这样做,以课堂方式进行,但这更接近您的要求:
$('#SiteDescriptions'+i).animate({opacity : 1 },500)
// I don't want to speculate on your dom structure, but if you are using id's
// you still need a way to prevent from fading out everything on the page that
// isn't the new action. So I am assuming that all the #SiteDescriptions are siblings
.siblings().not('#SiteDescriptions'+i).animate({opacity: 0}, 500);