Your problem is that you're never removing the old phase
class, so the new class is simply being added to the list.(您的问题是您永远不会删除旧的phase
类,因此新的类仅被添加到列表中。)
Add removeClass('AB C')
before adding the new phase class:(在添加新的阶段类之前,添加removeClass('AB C')
:)
$(this).children().eq(2).html(phase).addClass(cClass).removeClass('A B C').addClass(phase);
By using removeClass('AB C')
you don't have to worry about figuring out which phase class was currently set on the element, as this will remove them all.(通过使用removeClass('AB C')
您不必担心弄清楚当前在元素上设置了哪个阶段类,因为这将全部删除。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…