如果 <td> 为空,则无法隐藏 <tr>
Cannot hide <tr> if <td> are empty
我只想在 <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>";
}
?>
请问我哪里出错了?非常感谢。
如果字段为空,则无需打印整个 <tr>
元素。例如,
<?php
$basic_medical = the_field('basic_medical');
$comp_medical = the_field('comp_medical');
?>
<tbody>
<?php if(!empty($basic_medical) && !empty($comp_medical)): ?>
<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>
<?php endif; ?>
...
...
<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>
我只想在 <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>";
}
?>
请问我哪里出错了?非常感谢。
如果字段为空,则无需打印整个 <tr>
元素。例如,
<?php
$basic_medical = the_field('basic_medical');
$comp_medical = the_field('comp_medical');
?>
<tbody>
<?php if(!empty($basic_medical) && !empty($comp_medical)): ?>
<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>
<?php endif; ?>
...
...
<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>