我有一個表格顯示數據庫中的數據,並且我有一個帶有簡單算術函數的單元格。 我想隱藏總和爲零的整個行(如果$ sold值爲零)。根據html表單元格值隱藏行
<input type="button" id="btnHide" Value=" Hide Empty Rows " />
...
<tbody>
\t \t \t <?php }
\t
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$sold=$row['value1']+$row['value2']);
\t { ?>
<tr>
\t \t \t <td><?php echo $row['contract'] ?></td>
\t \t \t <td><?php echo (round($row['value1'], 2)) ?></td>
\t \t \t <td><?php echo (round($row['value2'],2)) ?></td>
\t \t \t <td><?php echo ((round($sold, 2))+0) ?></td>
\t </tr><?php } } ?>
</tbody>
我發現一些代碼隱藏所有行,它具有空單元格,但它不是我想要的。 Thx尋求幫助。
$(document).ready(function() {
$("#gdRows td").each(function() {
var cellText = $(this).text();
if ($.trim(cellText) == '') {
$(this).css('background-color', 'cyan');
}
});
$('#btnHide').click(function() {
$("#gdRows tr td").each(function() {
var cell = $.trim($(this).text());
if (cell.length == 0) {
$(this).parent().hide();
}
});
});
$('#btnReset').click(function() {
$("#gdRows tr").each(function() {
$(this).show();
});
});
});