繁体   English   中英

单击glyphicon时,将类添加到表行;再次单击时,将类删除

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

我可以在glyphicon单击上添加一个类,但不能将其删除。 这是我的小提琴

以下是我的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");
    });

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM