作为一些示例代码,我可能有这样的东西:
$('a.parent').click(function(){
$('a.parent').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
$(this).animate({
width: '160px'
},200,function(){
});
});
问题是我不希望被单击的元素动画到 140px 宽度,然后又回到 160px。
有没有办法只对集合中未被单击的元素运行“each”?或者,还有更好的方法?
你可以使用 :not(this) 所以改变:
$('a.parent').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
to :
$('a.parent:not('+this+')').each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
或者在 $('a.parent') 之后使用 .not(this) ,所以:
$('a.parent').not(this).each(function(){
$(this).stop(true,false).animate({
width: '140px'
},200,function(){
});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)