简体   繁体   English

如何仅获取具有值的html表行列?

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

I want to know if there is an easier way of getting only the html table row columns with values, 我想知道是否有一种更简单的方法来只获取带有值的html表行列,

here is a sample table image 这是示例表图像

在此处输入图片说明

and here is what I wanted it to become 这就是我想要它成为的

在此处输入图片说明

  <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> 

Here is my draft code, I'm not sure if I'm in the right path or if there's a simpler way of doing it, 这是我的代码草稿,我不确定自己走的路是否正确,或者是否有更简单的方法来做,

$.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("");
    }
})

After removing the values of "-" columns, I have to arrange the rows, and fill-in the gaps, 删除“-”列的值后,我必须排列行并填充间隙,

Is there any other way to make it simpler, 还有其他方法可以简化它,

Thank You,! 谢谢,!

You can try something like 您可以尝试类似

$(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