首页 > 解决方案 > 网站显示与目录中一样多的图像

问题描述

我想创建 HTML 网站,它将显示与目录中一样多的图像。可以有 5 个或 100 个。通过单击 NEXT/PREVIOUS 按钮,网站应显示目录中的单个图像。

        $(document).ready(function () {

            var images = [
                "Icons/1.PNG",
                "Icons/2.PNG",
                "Icons/3.PNG"
            ];

            var imageIndex = 0,
                iLength = images.length - 1,
                imageEl = $('#image'),
                prevEl = $('#previous'),
                nextEl = $('#hoger');

            prevEl.on("click", function () {
                imageIndex--;

                imageEl.attr('src', images[imageIndex]);

                nextEl.prop('disabled', false);
                prevEl.prop('disabled', !imageIndex);
            });

            nextEl.on("click", function () {
                imageIndex++;

                imageEl.attr('src', images[imageIndex]);

                nextEl.prop('disabled', imageIndex === iLength);
                prevEl.prop('disabled', false);
            });

            prevEl.prop('disabled', true);
            imageEl.attr(images[0]);
        });
    </script>

而不是列表中的图像var = images,我需要读取图像计数。

标签: javascripthtmlloops

解决方案


推荐阅读