Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript为目录中的所有文件创建链接?_Javascript_List_Cordova_Hyperlink - Fatal编程技术网

如何使用javascript为目录中的所有文件创建链接?

如何使用javascript为目录中的所有文件创建链接?,javascript,list,cordova,hyperlink,Javascript,List,Cordova,Hyperlink,我有这样的列表,但列出了目录中的所有内容,但我想创建一个链接,如果你点击文件,它会读取文件,如果它是目录,那么它会进入目录 e.g. the list is a (folder) b (folder) c (folder) d (folder) e (folder) f (folder) asdf.txt asdf.html asdf.ini 如果我点击文件夹a,它会进入a目录,如果我点击asdf.txt,它会显示txt中的内容 我有以下代码来创建所有内容,但不确定如何实现所有目录和文件的链接

我有这样的列表,但列出了目录中的所有内容,但我想创建一个链接,如果你点击文件,它会读取文件,如果它是目录,那么它会进入目录

e.g. the list is
a (folder)
b (folder)
c (folder)
d (folder)
e (folder)
f (folder)
asdf.txt
asdf.html
asdf.ini
如果我点击文件夹a,它会进入a目录,如果我点击asdf.txt,它会显示txt中的内容

我有以下代码来创建所有内容,但不确定如何实现所有目录和文件的链接

for(var I in entries)
{
    // creates li and /li
    var li = document.createElement('li');
    // creates the name of the contents
    li.appendChild(document.createTextNode(entries[I].name));
    ul.appendChild(li);
}
提前谢谢

编辑:这实际上是我尝试过的,但没有成功,所以我只是删除了它并发布了我的原创…我想我也应该发布这个

    var ul = document.getElementById('contentList');
    // for all the entries inside the directory loop the following
    for(var I in entries)
    {
        // creates li and /li
        var li = document.createElement('li');
        var a = document.createElement('a');
        // creates the name of the contents

        ul.appendChild(li);
        li.appendChild(a);
        a.appendChild(document.createTextNode(entries[I].name));
        a.href = (entries[I].name);
        li.appendChild(a);
        ul.appendChild(li);

这不只是
li.appendChild(“”)的问题吗还是创建指向文件和文件夹的差异化链接的挑战?

是不是很难弄清楚如何将
包含到你所拥有的内容中?DomI>是的,我知道…我看到了那篇文章,但不知怎的它不起作用Charliefl>尝试这一点并不难,但不知怎的它不起作用,所以我想@是的,差异化链接…我记得不是这样的在php方面很难,我相信它们在
a href=“$variableoffilename”
中的工作原理是一样的,但似乎不起作用O.oSo您想让它们在php中工作还是在JavaScript中工作?如果您发布生成文件和文件夹列表的代码以及在PHP中呈现HTML.oh的代码,这会更容易。但是我认为它们可能工作得非常简单。我对javascript非常不熟悉,但我希望代码能够在javascript中工作