JavaScript:如何加载文件夹中的所有图像? [英] JavaScript: how to load all images in a folder?

查看:111
本文介绍了JavaScript:如何加载文件夹中的所有图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var img = new Image();
img.src = "images/myFolder/myImage.png";

以上只会加载myImage.png。如何加载myFolder的所有图像?

The above will only load myImage.png. How to load all images of myFolder?

推荐答案

JavaScript无法直接访问文件系统的内容。你必须首先使用服务器端脚本(用PHP编写等)传递内容。

JavaScript can't directly access the contents of a file system. You'll have to pass the contents using a server-side script (written in PHP, etc) first.

然后,一旦你有了,你可以使用一个循环你的JavaScript可以单独加载它们。

Then once you have that, you can use a loop in your JavaScript to load them individually.

这篇关于JavaScript:如何加载文件夹中的所有图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆