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

后端 未结 14 1951
情深已故
情深已故 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:18

    $(document).ready(function(){
      var dir = "test/"; // folder location
      var fileextension = ".jpg"; // image format
      var i = "1";
    
      $(function imageloop(){
        $("").attr('src', dir + i + fileextension ).appendTo(".testing");
        if (i==13){
          alert('loaded');
        }
        else{
          i++;
          imageloop();
        };
      });   
    });
    

    For this script, I have named my image files in a folder as 1.jpg, 2.jpg, 3.jpg, ... to 13.jpg.

    You can change directory and file names as you wish.

提交回复
热议问题