如图所示点击News时加一层灰色背景而把Amplifiers的灰色背景去掉!!
第一次做的时候并没有发现还有兄弟级的这一说法所以我傻傻的给她们都加了class,
css
.top_bg{
background:#878787
}
jq
$('.top_two').click(function(){
$('.top_one,.top_three').removeClass('top_bg');
$('.top_two').addClass('top_bg');
});
$('.top_three').click(function(){
$('.top_one,.top_two').removeClass('top_bg');
$('.top_three').addClass('top_bg');
});
$('.top_one').click(function(){
$('.top_three,.top_two').removeClass('top_bg');
$('.top_one').addClass('top_bg');
});
});
后来才发现不用那么多代码几句就搞定了
一开始都给了class top_one top_two top_three这样,很麻烦
现在把她们都设置为一个class就行
$('.top_two').click(function(){
$('.top_two').siblings().removeClass('top_bg');
$(this).addClass('top_bg');
});