How to load all the images from one of my folder into my web page, using Jquery/Javascript

后端 未结 14 1981
情深已故
情深已故 2020-11-22 10:18

I have a folder named \"images\" in the same directory as my .js file. I want to load all the images from \"images\" folder into my html page using Jquery/Javascript.

<
14条回答
  •  失恋的感觉
    2020-11-22 11:01

    Use :

    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("");
            });
        }
    });
    

    If you have other extensions, you can make it an array and then go through that one by one using in_array().

    P.s : The above source code is not tested.

提交回复
热议问题