Loading Images from a Folder into Web Page with jQuery/Javascript
To load images from a folder named "images" into an HTML page, you can use JavaScript or jQuery. Even if the image names are not sequential numbers, there's a solution.
Solution:
<code class="js">var folder = "images/"; $.ajax({ url : folder, success: function (data) { $(data).find("a").attr("href", function (i, val) { if( val.match(/\.(jpe?g|png|gif)$/) ) { $("body").append( "<img src='"+ folder + val +"'>" ); } }); } });</code>
Explanation:
Considerations:
<code class="js">app.use('/images', serveIndex(path.join(__dirname, '/images')));</code>
By using this approach, you can easily load all images from your "images" folder into your web page, regardless of their names.
The above is the detailed content of How to Load Images from a Folder into Your Web Page with jQuery/Javascript?. For more information, please follow other related articles on the PHP Chinese website!