There are 0.png, 1.png, 2.png, ... in folder images. How to load all them. Number of the images unknown.
} 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);
Code:
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 + "'>");
});
}
});
This will load all the image .png present in a folder, care that this code use jquery.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.