【发布时间】:2020-10-21 04:40:35
【问题描述】:
只有当<td> 没有可用数据时,我才想隐藏<tr>。我尝试了许多脚本以及 if 条件。但没有运气。请帮忙。
<table class="table table-striped why-choose-tbl" id="insurance">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Basic</th>
<th scope="col">Comprehensive</th>
</tr>
</thead>
<tbody>
<tr>
<td>Medical</td>
<td><span><?php the_field('basic_medical') ?></span><i class="fas fa-check"></i></td>
<td><span><?php the_field('comp_medical') ?></span><i class="fas fa-check"></i></td>
</tr>
<tr>
<td>Cancellation</td>
<td><span><?php the_field('basic_cancellation') ?></span><i class="fas fa-check"></i></td>
<td><span><?php the_field('comp_cancellation') ?></span><i class="fas fa-check"></i></td>
</tr>
</tbody>
</table>
<script>
$('#insurance tr').filter(function() {
return $.trim($(this).text()) === '';
}).hide();
// $('#insurance > tbody > tr').has('td:empty').hide()
// $('#insurance > tbody > tr').each(function () {
// if ($(this).find('td').is(':empty')) {
// $(this).hide();
// }
// });
</script>
我也尝试如下。但他们都没有工作。
<?php
$basic = the_field('basic_medical');
$comp =the_field('comp_medical');
if (empty($basic) && empty($comp))
{
echo "<td style=/"display:none;/"><i class="fas fa-check"></i><span><?php the_field('basic_medical') ?> </span></td>";
echo "<td style=/"display:none;/"><i class="fas fa-check"></i><span><?php the_field('comp_medical') ?></span></td>";
}
?>
我可以知道我哪里出错了吗?非常感谢。
【问题讨论】:
-
与其在生成后隐藏,不如一开始就不要在PHP端生成
<tr>,如果没有数据可以放进去? -
你的 PHP if 语句逻辑是倒退的,你在声明:如果变量是空的,回显这个,而不是你应该做相反的事情:
if (empty($basic) === false && empty($comp) === false)并且不要回显`style=/"显示:无;/“`.
标签: javascript php jquery wordpress advanced-custom-fields