选择下一个或上一个图像


Select next or previous image

  • 代码从目录中选择图像并将其显示在表格中。这是我想要的,但无法使用"上一个"或"下一个"按钮来显示下一个图像。我看过很多网站和Stack,但没有运气,任何帮助都非常感谢

            <?php function RandomImage()
            {
                $randnum = 0;
                print("<UL>'n");
                $myDir = dir("./images");
                $icount = 1;
                while($entryName = $myDir->read())
                {       
                    $icount++;
                }
                $myDir->close();
                $myDir = dir("./images");
                rewinddir();
                srand(time());
                $randnum = rand(3,($icount-2)+1);
                for($i=0;$i<$randnum;$i++)
                {   
                    $entryName = $myDir->read();
                    $myimage = $entryName;
                }
                return('images/' . $myimage);
            }
            ?>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <title>Club Photo's</title>
            </head>
            <body>
            <?php
                $picture = RandomImage();
                echo $picture;
            ?>
            <table width="250" height="237" border="2" cellpadding="0" cellspacing="3">
                <tr>
                    <br><td><div align="center">Club Photo's </div></td><br>
                </tr>
                <tr>
                    <td><img name="myImage" src="<?php echo $picture; ?>" width="460" height="315" alt=""></td>
                </tr>
            </table>
            <br><input name="Previous" type="button" value="previous" />
            <input name="Next" type="button" value="next" onClick=img name="myImage" src="<?php echo $picture; ?>"/> 
            </body>
    

简单地放置两个html按钮,如果假设您一次显示六个图像,那么当用户单击下一个按钮时,只需隐藏第一个图像并显示第七个图像,然后通过css等隐藏它…上一个按钮也是如此。请记住,当显示最后六个图像时,下一个按钮不应隐藏该部分中的第一个元素。。