所以我一直在制作一个家庭实验室仪表板,我需要知道如何在显示我的 php 数组后添加响应式“显示更多”按钮。我对开发还很陌生,它更多的是作为一种爱好。下面是我目前的设置方式,但如果 torrent 数组中有超过 15 个元素,它就会变得很长。任何建议都会有帮助。
<div class="row">
<!--Downloading Section-->
<div class="col-lg-6 col-md-3 col-sm-12 col-xs-12">
<div class="info-box blue-bg">
<h3>Downloading <span class="speeds">
<?php
if ($client == "qbittorent"){
echo round(intval($global_info['dl_info_speed'])/1000, 2) . " kB/s";
} elseif ($client == "transmission"){
echo round(intval($global_info['downloadSpeed'])/1000, 2) . " kB/s";
}
?>
</span></h3>
<?php
if($torrents == null){
echo "There was a problem fetching torrents.";
} else {
if ($client == "qbittorrent"){
foreach($torrents as $torrent){
if($torrent['state'] == "downloading"){
echo $torrent['name'] . "<br>";
}
}
} elseif ($client == "transmission"){
foreach($torrents['torrents'] as $torrent){
if($torrent['status'] == "4"){
echo $torrent['name'] . "<br>";
}
}
}
}
?>
</div><!--/.info-box-->
</div><!--/.col-->
最佳答案
有两种方法可以做到这一点。
- AJAX:使用 javascript 检测按钮何时被单击,然后将包含结果的 ajax 调用提交到页面,然后将结果添加到页面
- 可见切换:打印出所有结果,就像您现在所做的那样,但隐藏 15 之后的所有结果(即
style="display:none"
)。然后使用 JavaScript 检测按钮点击,并切换可见性以显示隐藏的结果。
关于javascript - 查看 php 数组的更多按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40915068/