我每页显示一定数量的图像。我想为任何页面上显示的图像数量设置最大限制,例如设置一个属性,以便显示不超过八个。我已经用 PHP 编写了这个逻辑,但我仍然看到所有图像都显示在任何给定页面上,忽略了我设置的任何限制。代码:
$counter = 0;
foreach ($device as $value) {
$entry = $value;
echo "<head>";
echo '<script type="text/javascript">',
'window.setInterval(function() { ',
"document.getElementById('$counter').src='/latimage.php?&dev=$entry&random='+new Date().getTime();",
'},1000)',
'</script>';
echo "</head>";
echo "<body onLoad='setTimeout('refresh()',1000)'>";
echo "<td>$entry<img id= '$counter' width='100%' height='auto'></img></td>";
$counter = $counter + 1;
if ($counter == 4 || $counter == 8) {
echo " <tr>";
}
最佳答案
最好的方法是只从数据库中获取 8 张图像,而不是一次获取所有图像。使用分页设置每页的限制和偏移量。
关于javascript - 如何限制每页显示的图像数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717496/