簡體   English   中英

如何僅獲取具有值的html表行列?

[英]How to get only html table row columns with values?

我想知道是否有一種更簡單的方法來只獲取帶有值的html表行列,

這是示例表圖像

在此處輸入圖片說明

這就是我想要它成為的

在此處輸入圖片說明

  <table id="tblPayslipApproval" cellspacing="0" border="0"> <tbody> <tr class="tr-border-full"> <td style="min-width:50px">EARNINGS</td> <td style="min-width:50px"></td> <td style="min-width:50px" class="td-border-right"></td> <td style="min-width:50px" align="center" colspan="3" class="td-border-right">DEDUCTIONS</td> <td style="min-width:50px" align="center" colspan="3" class="td-border-right">LOAN BALANCES</td> </tr> <tr class="tr-border-full"> <td style="min-width:50px">DESCRIPTION</td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right">AMOUNT</td> <td style="min-width:50px">DESCRIPTION</td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right">AMOUNT</td> <td style="min-width:50px">DESCRIPTION</td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right">AMOUNT</td> </tr> <tr> <td style="min-width:50px" class="td-border-left">&nbsp;</td> <td style="min-width:50px">&nbsp;</td> <td style="min-width:50px" class="td-border-right">&nbsp;</td> <td style="min-width:50px">&nbsp;</td> <td style="min-width:50px">&nbsp;</td> <td style="min-width:50px" class="td-border-right">&nbsp;</td> <td style="min-width:50px">&nbsp;</td> <td style="min-width:50px">&nbsp;</td> <td style="min-width:50px" class="td-border-right">&nbsp;</td> </tr> <tr> <td style="min-width:50px" class="td-border-left">Basic Pay</td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"><span id="preview_basic_pay"> 18,655.88 </span></td> <td style="min-width:50px">SSS EE Contribution</td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"><span id="preview_sss_ee_contrib1"> 581.30 </span></td> <td style="min-width:50px"></td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"><span id="preview_sss_ee_contrib2"></span></td> </tr> <tr> <td style="min-width:50px" class="td-border-left"></td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"></td> <td style="min-width:50px">PhilHealth EE Contribution</td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"><span id="preview_philhealth_ee_contrib1"> 256.52 </span></td> <td style="min-width:50px"></td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"></td> </tr> <tr> <td style="min-width:50px" class="td-border-left"> </td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"></td> <td style="min-width:50px">PAGIBIG EE Contribution</td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"><span id="preview_pagibig_ee_contrib1"> 100.00 </span></td> <td style="min-width:50px"></td> <td style="min-width:50px"></td> <td style="min-width:50px" class="number-align td-border-right"></td> </tr> </tbody> </table> 

這是我的代碼草稿,我不確定自己走的路是否正確,或者是否有更簡單的方法來做,

$.each("table > tbody > tr:nth-child(3)", function(){
    var $elem = $(this);
    if($elem.text() == " - "){
       $elem.prev().text("");
       $elem.text("");
    }
})

$.each("table > tbody > tr:nth-child(6)", function(){
    var $elem = $(this);
    if($elem.text() == " - "){
       $elem.prev().text("");
       $elem.text("");
    }
})

$.each("table > tbody > tr:nth-child(9)", function(){
    var $elem = $(this);
    if($elem.text() == " - "){
       $elem.prev().text("");
       $elem.text("");
    }
})

刪除“-”列的值后,我必須排列行並填充間隙,

還有其他方法可以簡化它,

謝謝,!

您可以嘗試類似

$(document).ready(function () {

    $("#tblPayslipApproval tr").find("td:contains('-')").each(function(k,v){
        $(v).prev().prev().html("");
        $(v).html("");
    });


});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM