php - 如果为空则隐藏 HTML/JQuery 表格(footable)

标签 php jquery html css

下面是我网站的源代码,它显示了一个由没有数据填充的 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 :

https://jsfiddle.net/jsb3z0y4/

关于php - 如果为空则隐藏 HTML/JQuery 表格(footable),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35539595/

相关文章:

javascript - 获取输入值javascript

php - 从 db 检索数据并将其显示在 php 的表中。看到这段代码有什么问题吗?

php - 如何让 Nightwatch 测试在 CircleCI 中运行?

javascript - 有没有办法让选择的内容下推?

javascript - Bootstrap Modal 使用数据图像作为源

html - 长 URL(超过设备宽度)的响应式解决方案

javascript - 在 JavaScript 中分配样式表会创建良好的 html,但不会显示样式

php - Sphinx 搜索 php - 良好实践

php - 新手 php 正则表达式问题

jquery - 将一个 div 放在另一个 div 之上