下面是我网站的源代码,它显示了一个由没有数据填充的 PHP 文件生成的空表,如果表是空的,我如何隐藏这些表并从页面中删除代码。
<form class="cart" method="post" enctype='multipart/form-data'>
<table class="footable" cellspacing="0" class="group_table">
<thead>
<tr id="price-table-custom-header">
<th><center>head1</center></th>
<th><center>Information</center></th>
<th data-sort-initial="true"><center>head3</center></th>
<th><center>Purchase</center></th>
</tr>
</thead>
<tbody> </tbody>
<tfoot class="hide-if-no-paging">
<tr>
<td colspan="4">
<div class="pagination pagination-centered">
<ul></ul>
</div>
</td>
</tr>
</tfoot>
</table>
最佳答案
您可以验证 tbody 标签是否为空,如果是则隐藏整个表格。
$(document).ready(function(){
if ($.trim($(".group_table tbody").text()).length == 0) {
$('.group_table').hide();
}
});
编辑:
你的表有两个类属性,要添加两个类,你应该这样做:
<table cellspacing="0" class="group_table footable">
Js fiddle :
关于php - 如果为空则隐藏 HTML/JQuery 表格(footable),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35539595/