mam rozwijane menu w postaci drzewa. problem pojawia sie gdy chce wybrac inna pozycje z menu (np. link mapa.html)nie bedace w podmenu tego drzewa (1.html, 2.html, 3.html). co zrobic aby po wyborze drzewo zawierajce wymienione pozycje chowalo sie?
ponizej kod pliku menu
<body bgcolor="black"><font color="white"> <ul id="tree0" class="tree">
<li><a class="menu_link" href="mapa.html" style="color:white" target="zmienna">Strona główna
</a></li>
<li><a href="tabela.html" style="color:red" target="zmienna">dane
</a></li> <li><a href=#1>Archiwum
</a>
<li> <a href="1.html" style="color:yellow" target="zmienna"> opcja1
</a> </li> <li> <a href="2.html" style="color:blue" target="zmienna">opcja2
</a> </li> <li> <a href="3.html" style="color:green" target="zmienna"> opcja3
</a> </li> <li><a href="galeria/galeria.html" style="color:red" style="color:white" target="zmienna">Galeria
</a></li>
<script type="text/javascript"> <!--
new tree("tree0");
//-->
tutaj zas jest skrypt js do ktorego odwoluja sie linki podmenu. w kodzie znajduje sie odwolanie do gifow, ale ja akurat nie korzystam z tego.
function tree(id)
{
this.id = id;
this.click = function ()
{
for (var i = 0, el_node; i < this.parentNode.childNodes.length; i++)
{
el_node = this.parentNode.childNodes.item(i)
if (el_node.nodeName.toLowerCase() == 'ul')
{
el_node.style.display = el_node.style.display == 'none' ? 'block' : 'none';
this.parentNode.style.backgroundImage = 'url("' + (el_node.style.display == 'none' ? 'closed' : 'opened') + '.gif")';
return;
}
}
}
this.start = function (el)
{
for (var i = 0, el_node; i < el.childNodes.length; i++)
{
el_node = el.childNodes.item(i);
if (el_node.nodeName.toLowerCase() == 'a')
{
el_node.onclick = this.click;
for (var j = 0; j < el_node.parentNode.childNodes.length; j++)
{
if (el_node.parentNode.childNodes.item(j).nodeName.toLowerCase() == 'ul')
{
el_node.parentNode.style.backgroundImage = 'url("closed.gif")';
el_node.className = (el_node.className ? el_node.className + ' ' : '') + 'folder';
break;
}
if (el_node.parentNode.childNodes.item(j).nodeName.toLowerCase() == 'li') break;
}
if (el_node.href && unescape(el_node.href) == unescape(window.location.href))
{
el_node.className = 'active';
var el_parentNode = el_node;
do
{
el_parentNode = el_parentNode.parentNode;
if (el_parentNode.nodeName.toLowerCase() == 'ul')
{
el_parentNode.style.display = 'block';
if (document.getElementById(this.id) != el_parentNode) el_parentNode.parentNode.style.backgroundImage = 'url("opened.gif")';
}
}
while (document.getElementById(this.id) != el_parentNode)
}
}
else if (el_node.nodeName.toLowerCase() == 'ul') el_node.style.display = 'none';
this.start(el_node);
}
}
if (document.getElementById && document.childNodes)
{
if (document.images)
{
new Image().src = 'opened.gif';
new Image().src = 'document.gif';
}
this.start(document.getElementById(this.id));
}
}
Ten post edytował Adyk 1.06.2006, 14:36:10