【问题标题】:How I create a Read More button inside a table?如何在表格内创建阅读更多按钮?
【发布时间】:2017-03-30 08:59:37
【问题描述】:
<?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 有什么关系?

【问题讨论】:

  • 你可以使用 ajax 来实现。在该按钮上单击(阅读更多)使用 ajax 调用添加新的 trs。点击此链接:/load-more-data-using-jquery-ajax-php-from-database 这是一个从数据库加载更多/读取更多数据并将其放入 html 的示例。

标签: javascript php wordpress foreach


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2015-06-22
    • 2020-09-23
    • 2021-08-22
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多