Well, I know that with some jQuery actions, we can add a lot of classes to a particular div:
<div class="cleanstate"></div>
假设通过一些单击和其他操作,div获得了很多类
<div class="cleanstate bgred paddingleft allcaptions ..."></div>
那么,我如何删除除一个类之外的所有类呢?我唯一想到的是:
$('#container div.cleanstate').removeClass().addClass('cleanstate');
虽然removeClass()
会杀死所有的类,div会搞砸,但在这之后再加上addClass('cleanstate')
,它就会恢复正常.另一个解决方案是将ID属性与基本CSS属性放在一起,这样它们就不会被删除,这也会提高性能,但是我只想知道另一个解决方案,可以除go ".lean state"之外的所有属性
I'm asking this because, in the real script, the div suffers various changes of classes.