【发布时间】:2013-11-30 15:07:52
【问题描述】:
我有这样的列表,但列出了目录中的所有内容,但我想创建一个链接,如果您单击该文件,它也会读取该文件,如果它是一个目录,那么它将进入该目录..
e.g. the list is
a (folder)
b (folder)
c (folder)
d (folder)
e (folder)
f (folder)
asdf.txt
asdf.html
asdf.ini
如果我点击文件夹 a,那么如果我点击 asdf.txt,它将进入 a 目录,然后它会显示 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);
【问题讨论】:
-
很难弄清楚如何将
<a>包含到您拥有的内容中吗? -
DomI> 是的,我知道...我看到了那个帖子,但不知何故它不起作用
-
charliefl> 尝试起来并不难,但不知何故它不起作用,所以我喜欢@_@
标签: javascript list cordova hyperlink