繁体   English   中英

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

[英]How to load images from folder by using javascript

文件夹图像中有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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM