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

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

    You can use the fs.readdir or fs.readdirSync methods to get the file names in the directory.

    The difference between the two methods, is that the first one is asynchronous, so you have to provide a callback function that will be executed when the read process ends.

    The second is synchronous, it will returns the file name array, but it will stop any further execution of your code until the read process ends.

    After that you simply have to iterate through the names and using append function, add them to their appropriate locations. To check out how it works see HTML DOM and JS reference

提交回复
热议问题