注册 登录
编程论坛 JavaScript论坛

树形导航问题

ztslove 发布于 2010-06-22 00:12, 605 次点击
调试了好几次   就是不行   大家    看下 那里出错了   困了 实在是看不出来了  谢谢···
程序代码:

<style type="text/css">
<!--
    a{text-decoration:none}
    #productsmenu , #supportmenu, #contactmenu{
      display:none;
  }
-->
</style> <ul>

 <li><a id="products" href="#">[+] Products</a>
   <ul ID="productsmenu">
      <li><a href="prodlist.html">Product List</a></li>
      <li><a href="order.html">Order Form</a></li>
      <li><a href="pricelist.html">Price List</a></li>
   </ul>

 </li>

 <li><a id="support" href="#">[+] Support</a>
   <ul id="supportmenu">
      <li><a href="sforum.html">Support Forum</a></li>
      <li><a href="scontact.html">Contact Support</a></li>
   </ul>

 </li>

 <li><a ID="contact" href="#">[+] Contact Us</a>
   <ul id="contactmenu">
      <li><a href="contact1.html">Service Department</a></li>
      <li><a href="contact2.html">Sales Department</a></li>
   </ul>

 </li>
</ul>

<script language="javascript">

function Toggle(e) {

if(!document.getElementById) return;
if(!e) var e = window.event;
whichlink = (e.target) ? e.target.id : e.srcElement.id;
obj=document.getElmentById(whichlink + "menu");
visible=(obj.style.display=="block")
key=document.getElementById(whichlink);
keyname=key.firstChild.nodeValue.substring(3);
if (visible){
    obj.style.display="none";
    key.firstChild.nodeValue = "[+]" + keyname;
}else{
    obj.style.display="block";
    key.firstChild.nodeValue = "[-]" + keyname;

    }
}

    document.getElementById("products").onclick=Toggle;
document.getElementById("support").onclick=Toggle;
document.getElementById("contact").onclick=Toggle;


</script>

2 回复
#2
zmh8862010-06-22 18:20
37行单词拼写错误 应为 getElementById
#3
ztslove2010-06-22 23:13
呵呵  谢谢啊  可以了  昨晚  太晚了 有点困   没看清 ···  不过我好有哦一个小问题  就是  我把 JavaScript 代码  放到  有序列表的 上面  就不行  这是为什么啊 像下面这样:
程序代码:
<style type="text/css">
<!--
    a{text-decoration:none}
    #productsmenu , #supportmenu, #contactmenu{
      display:none;
  }
-->
</style>

<script language="javascript">

function Toggle(e) {

if(!document.getElementById) return;
if(!e) var e = window.event;
whichlink = (e.target) ? e.target.id : e.srcElement.id;
obj=document.getElementById(whichlink + "menu");
visible=(obj.style.display=="block")
key=document.getElementById(whichlink);
keyname=key.firstChild.nodeValue.substring(3);
if (visible){
    obj.style.display="none";
    key.firstChild.nodeValue = "[+]" + keyname;
}else{
    obj.style.display="block";
    key.firstChild.nodeValue = "[-]" + keyname;

    }
}

    document.getElementById("products").onclick=Toggle;
document.getElementById("support").onclick=Toggle;
document.getElementById("contact").onclick=Toggle;


</script>

 <ul>
<li><a id="products" href="#">[+] Products</a>
   <ul ID="productsmenu">
      <li><a href="prodlist.html">Product List</a></li>
      <li><a href="order.html">Order Form</a></li>
      <li><a href="pricelist.html">Price List</a></li>
   </ul>
</li>
<li><a id="support" href="#">[+] Support</a>
   <ul id="supportmenu">
      <li><a href="sforum.html">Support Forum</a></li>
      <li><a href="scontact.html">Contact Support</a></li>
   </ul>
</li>
<li><a ID="contact" href="#">[+] Contact Us</a>
   <ul id="contactmenu">
      <li><a href="contact1.html">Service Department</a></li>
      <li><a href="contact2.html">Sales Department</a></li>
   </ul>
</li>
</ul>

1