我看到您正在使用JQuery——所以让我们坚持这一点。
你在绕圈子
ol
但你想绕过去
ol
是的
li
s
所以,替换
$('ol.progress').each....
通过
$('ol.progress li').each....
可以使用
.removeClass()
没有任何参数。
但既然你想保留
active
-类你必须保留这个属性——在我的代码版本(见下文)中,我将为此使用一个变量。
此外,您希望替换HTML部分,而不是文本部分,这样您的代码片段就可以读取
$('ol.progress li').each(function () {
var is_active = false;
is_active = $(this).hasClass('active');
$(this).removeClass();
if(is_active){
$(this).addClass('active');
}
var newcontent = '<a href="#">' + $(this).html() + "</a>";
$(this).html(newcontent);
});