如何在Javascript中迭代文件 [英] How can I iterate through files in Javascript

查看:67
本文介绍了如何在Javascript中迭代文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Javascript中迭代一组文件?我正在编写一个jQuery插件,它接受一个图像数组,或者,我希望,一个包含图像列表的目录。例如。要么:

Is it possible to iterate through a collection of files in Javascript? I am writing a jQuery plugin that takes either an array of images or, I was hoping, a directory containing a list of images. E.g. either:

['image1.jpg','image2.jpg','image3.jpg']

'http://somedomain.com/images/'

然后,我希望能够遍历上述域并从文件夹中的每个文件中获取文件名。

I would then like to be able to iterate through the above domain and take the file name from each of the files in the folder.

我已经阅读了有关 FileSystemObject 的信息,但这将是仅在IE中可用,是否有可用于所有浏览器的等效项?

I have read about the FileSystemObject but this will only be available in IE, is there an equivalent that can be used in all browsers?

推荐答案

您应该使用服务器端语言来提供JSON或类似的图像数组。 Javascript无法访问本地文件。这将是严重的安全问题。

You should use server side language to provide array of images in JSON or similar. There is no way Javascript can access local files. That would be serious security issue.

这篇关于如何在Javascript中迭代文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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