单击字形图标时将 class 添加到 table 行,再次单击时删除

Add class to table row when glyphicon is clicked and remove when clicked again

我可以在点击字形图标时添加 class 但不能删除它。这是我的 fiddle

以下是我的jQuery。我想添加一个 if 语句 if hasClass then remove else addClass "success"

 jQuery(function($){
    $("tbody").on("click",".questCompletion > .glyphicon-ok", function(){
            $(this).parents("tr").addClass("success");
    });

});

使用toggleClass

 jQuery(function($){
    $("tbody").on("click",".questCompletion > .glyphicon-ok", function(){
            $(this).parents("tr").toggleClass("success");
    });

});