如何使用jQuery/Javascript将一个文件夹中的所有图像加载到我的网页中我在我的.js文件所在的目录中有一个名为“映像”的文件夹。我希望使用jQuery/Javascript将“图像”文件夹中的所有图像加载到我的html页面中。由于图像的名称不是连续整数,我该如何加载这些图像?
3 回答
慕雪6442864
TA贡献1812条经验 获得超5个赞
$filenameArray = [];$handle = opendir(dirname(realpath(__FILE__)).'/images/');
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
array_push($filenameArray, "images/$file");
}
}echo json_encode($filenameArray);$.ajax({
url: "getImages.php",
dataType: "json",
success: function (data) {
$.each(data, function(i,filename) {
$('#imageDiv').prepend('<img src="'+ filename +'"><br>');
});
}
});添加回答
举报
0/150
提交
取消
