如何在表中创建Read More按钮

How I create a Read More button inside a table?

本文关键字:Read More 按钮 创建      更新时间:2023-09-26
<?php $counter = 0 ?>
<table>
  <?php foreach($attributes as $a): ?>
  <tr>
    <td><?php $a['name']?></td>
    <td><?php $a['Price']?></td>
  </tr>
  <?php $counter++;
    if ($counter > 3) ?> <!-- What to do here? -->
<?php endforeach; ?>
</table>

在这样的PHP块中,我想在三个tr元素之后获得一个阅读更多按钮,当我单击按钮时显示所有其余的元素…

跟PHP有关吗?

不,它与php无关。如果你不想重载整个页面,你需要JavaScript来实现它。

在PHP中,您可以将短版本和长版本打印到单独的div中,然后在View-More-Button上使用以下JS-Code:

document.getElementById("shortId").style.display = "none";
document.getElementById("longId").style.display = "block";