JavaScript生成树的问题!!!!!!!!!!!!
在CODEPROJECT里找到了一个例子,是关于如何来生成树的。它是用DIV来显示或隐藏来控制树的。
但是例子中的结点只是一个字符,不能加链接,一回链接,树的展开功能就没有了。不知道哪位高手可以指点一两,谢谢:
function Toggle(node)
{
// Unfold the branch if it isn't visible
if (node.nextSibling.style.display == 'none')
{
// Change the image (if there is an image)
if (node.children.length > 0)
{
if (node.children.item(0).tagName == "IMG")
{
node.children.item(0).src = "minus.gif";
}
}
node.nextSibling.style.display = '';
}
// Collapse the branch if it IS visible
else
{
// Change the image (if there is an image)
if (node.children.length > 0)
{
if (node.children.item(0).tagName == "IMG")
{
node.children.item(0).src = "plus.gif";
}
}
node.nextSibling.style.display = 'none';
}
}
HTML里的结构如下:
<TR><TD>
<TABLE BORDER=0><TR><TD><IMG SRC="leaf.gif"> Analysis<DIV>
</DIV></TD></TR></TABLE>
</TD></TR>
<TR><TD>
<TABLE BORDER=0>
<TR><TD><A onClick="Toggle(this)" ><IMG SRC="minus.gif" > Implementation</A><DIV>
<TABLE BORDER=0><TR><TD WIDTH=10></TD><TD><IMG SRC="leaf.gif"> PHP<DIV>
</DIV></TD></TR></TABLE>
<TABLE BORDER=0><TR><TD WIDTH=10></TD><TD><A onClick="Toggle(this)"><IMG SRC="minus.gif"> <A href = "af">Visual C++</A></A><DIV>
<TABLE BORDER=0><TR><TD WIDTH=10></TD><TD><IMG SRC="leaf.gif"> Memory Leak problems<DIV>
</DIV></TD></TR></TABLE>
<TABLE BORDER=0><TR><TD WIDTH=10></TD><TD><IMG SRC="leaf.gif"> Database problems<DIV>
</DIV></TD></TR></TABLE>
。。