gpt4 book ai didi

javascript - 如何仅获取带有值的 html 表格行列?

转载 作者:行者123 更新时间:2023-12-03 02:10:09 25 4
gpt4 key购买 nike

我想知道是否有一种更简单的方法来仅获取带有值的 html 表格行列,

这是一个示例表格图像

enter image description here

这就是我想要的结果

enter image description here

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


});

关于javascript - 如何仅获取带有值的 html 表格行列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49612386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com