开发者

Foreach file in directory jQuery

How can I do a fore开发者_如何学Cach(File file in Directory) kind of thing in jQuery.

Thank you!


Javascript does not have access to the local file system for obvious security reasons. This is not possible.

Unless you are trying to loop through files on your server, in which case you wouldn't want to use jQuery anyway but something like ASP.NET or PHP or whatever framework you are using.


$('selector').each(function(idx, elm){
    //some code
});

Will allow you to iterate over a list, applying the same function to each. However, accessing the filesystem is not possible.


It is not possible with javascript/jquery to read contents of a directory for security reasons. Imagine you are trying to read the file system of client machine. You can use FSO (File System Object) but that works only in IE. You can use server-side languages such as PHP, ASP.Net for accessing the file system.

If you meant a loop with each, consider the each method of though. Example:

$('selector').each(function(){
  // your code.....
});


If the files are on the client you can't access them for security reasons.

If the files are on the server and you want process the list sever-side you wouldn't use JQuery as it's for client-side scripting.

If the files are on the server and you want to process the list client-side, you could generate the list in the server code and send it down as xml, json, etc.

If the files are on somebody else's server your only options is to recursivly follow links on their site, which is not really something you'd want to be doing with Javascript from a client's browser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜