我有一个带图片的文件夹。我想检索这些图像的所有“url”以创建带有相应“src”的“img标签”,并将它们放在“div”中。我怎么能用AJAX / Jquery做到这一点?
// What I have :
myFolder |
| - image_01.jpg
| - image_02.jpg
| - image_03.jpg
| - ...
// What I want :
<div id="myDiv">
<img src="http://www.example.com/myFolder/image_01.jpg" />
<img src="http://www.example.com/myFolder/image_02.jpg" />
<img src="http://www.example.com/myFolder/image_03.jpg" />
...
</div>
答案 0 :(得分:-1)
试试这个:
$(function(){
function lpadZeros(str, max) {
str = str.toString();
return str.length < max ? lpadZeros("0" + str, max) : str;
}
for(var i=1;i<100;i++){
var imgObj = $('<img/>');
imgObj.load(function() {
var thisimg = this;
$('#myDiv').append(thisimg);
});
imgObj.attr('src', 'http://www.example.com/myFolder/image_' + lpadZeros(i, 2) + '.jpg');
}
});