【发布时间】:2013-01-29 09:59:25
【问题描述】:
我想在添加像 type-two 这样的新类之前删除像 type-one 这样的匹配类
HTML:
<div class="demo test">
<span>One</span>
<span>Two</span>
<span>Three</span>
</div>
jQuery :
$(document).on("click" ,".demo > span", function(){
$(this).addClass("active").siblings().removeClass("active");
$(this).parents(".demo").removeClass(function(i, c){
return c.match(/type-[a-z]{0,5}/);
})
$(this).parents(".demo").addClass("type-"+$(this).text().toLowerCase());
})
我的代码还在不断添加,无法移除旧的匹配类。
我做错了什么?
【问题讨论】:
标签: javascript jquery regex match