gpt4 book ai didi

javascript - 如何使用javascript从文件夹加载图像

转载 作者:行者123 更新时间:2023-12-03 08:08:53 24 4
gpt4 key购买 nike

文件夹images中有0.png、1.png、2.png、...。如何加载所有这些。图片数量未知。

} while(!img[numOfImages].onerror);

alert("numOfImages = " + numOfImages);

var
numOfImages = 0;
img = [];

do{
img[numOfImages] = new Image();
img[numOfImages].src = "images/" + numOfImages + ".png";
numOfImages++;
} while(!img[numOfImages].onerror);
alert("numOfImages= " + numOfImages);

最佳答案

代码:

    var dir = "Src/themes/base/images/";
var fileextension = ".png";
$.ajax({
//This will retrieve the contents of the folder if the folder is configured as 'browsable'
url: dir,
success: function (data) {
//List all .png file names in the page
$(data).find("a:contains(" + fileextension + ")").each(function () {
var filename = this.href.replace(window.location.host, "").replace("http://", "");
$("body").append("<img src='" + dir + filename + "'>");
});
}
});

这将加载文件夹中存在的所有图像 .png,请注意此代码使用 jquery。

关于javascript - 如何使用javascript从文件夹加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34239130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com