这是我的主表,我想得到当前显示的项目的“功能”、“修复”、“谴责”、“被盗”的总和。
我的问题是,即使我应用过滤器,它仍然返回所有的总和,即使它没有显示在我的表上。
<p><span>Functional: <span id="functional"></span></span> <span>Repair: <span id="repair"></span></span>
<table id="emp-table">
<thead>
<th col-index = 1>ID</th>
<th col-index = 2>BATCH
<select class="table-filter" onchange="filter_rows(), asd()">
<option value="all">ALL</option>
</select>
</th>
<th col-index = 3>DISTRICT
<select class="table-filter" onchange="filter_rows(), asd()">
<option value="all">ALL</option>
</select>
</th>
<th col-index = 4>SCHOOL
<select class="table-filter" onchange="filter_rows(), asd()">
<option value="all">ALL</option>
</select>
</th>
<th col-index = 5>FUNCTIONAL
<!-- <select class="table-filter" onchange="filter_rows()">
<option value="all">ALL</option>
</select> -->
</th>
<th col-index = 6>REPAIR
</th>
<th >TOTAL</th>
</thead>
<?php
if($query_run)
{
foreach($query_run as $row)
{
?>
<tbody>
<tr class="inputItem">
<td > <?php echo $row['id']; ?> </td>
<td> <?php echo $row['pck_no']; ?> </td>
<td> <?php echo $row['district']; ?> </td>
<td> <?php echo $row['school_name']; ?> </td>
<td class="sample"> <?php echo $row['functional']; ?> </td>
<td class="sample1"> <?php echo $row['repair']; ?> </td>
<td id=TotMarks></td>
</tr>
</tbody>
<?php
}
}
else
{
echo "No Record Found";
}
?>
</table>
<span id="val"></span>
</div>
</div>
这是我的脚本,它发生在每个下拉菜单中,不更改值
<script>
function asd(){
var table = document.getElementById("emp-table"), sumVal = 0, sumrepair = 0;
for(var i = 1; i < table.rows.length; i++)
{
sumVal = sumVal + parseInt(table.rows[i].cells[4].innerHTML);
sumrepair = sumrepair + parseInt(table.rows[i].cells[5].innerHTML);
}
I want to the value of functional changes of sum if the dropdown is changes.
# This is the display of total of functional
document.getElementById("functional").innerHTML = sumVal;
document.getElementById("repair").innerHTML = sumrepair;
}
</script>
1条答案
按热度按时间fdbelqdn1#
检查一下过滤器的工作原理,它应该从DOM中删除行,否则如果它只是在视觉上隐藏它们(可能是用CSS),那么你的javascript将总是计算所有行(我假设现在发生了什么)。