jquery给表格某一列添加css样式

1、给table某一列动态添加class

  <td><span id="status" class="badge">${
    
    projects.proAudit}</span></td>
$ ('table tr td #status').each (function ()
        {
    
    
            var status=$(this).html();
            if (status=="审批通过"){
    
    $(this).addClass("bg-danger-light")}
             else if (status=="等待审核")
            {
    
    
                $(this).addClass("bg-info-light")
            }
            else if (status=="不通过")
            {
    
    
               //$(#status).addClass("bg-warning-light")不能用这个
                $(this).addClass("bg-warning-light")
            }

        });

注意要用$(this)给当前单元格添加class,若是用$(#status).addClass("bg-warning-light"),遍历时$(#status)获取的总是第一行的单元格内容

猜你喜欢

转载自blog.csdn.net/L221545/article/details/124078278
今日推荐