jqueryはテーブルの列にCSSスタイルを追加します

1. テーブルの特定の列にクラスを動的に追加します。

  <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)現在のセルにクラスを追加する必要があることに注意してください。これを使用すると、$(#status).addClass("bg-warning-light")トラバース時に$(#status)常に最初の行のセルの内容が取得されます。

おすすめ

転載: blog.csdn.net/L221545/article/details/124078278