最少代碼寫成的javascript menu tree

來源:互聯網
上載者:User

沒有圖片,沒有外部的js檔案,沒有css檔案,只有一個52行的html檔案.不過可擴充性很好,你可以輕易加片和超連結.

修改自 Marcelo Franco的版本,他的版本使用了table並且假定div只能用於tree menu.按照現代的web編程慣例不一定是可接受的.據Marcelo Franco說適用的瀏覽器是 Microsoft Internet Explorer 4+, Netscape 4+, etc.),我在我的瀏覽器上(IE6,opera8.52, firefox1.5)測了下我的簡化版本,好像也沒有什麼問題.

以下就是全部的原始碼

<html><head><title>Tree Menu</title></head><script language="javascript" type="text/javascript"><!--function tog(item){   obj=document.getElementById(item);   visible=(obj.style.display!="none");   key=document.getElementById("x" + item);   if (visible) {     obj.style.display="none";     key.innerHTML="+";   } else {      obj.style.display="block";      key.innerHTML="-";   }}  function expall(item,yes){   obj=document.getElementById(item);   arr=obj.getElementsByTagName("UL");   for (i=0;i<arr.length;i++) {     key=document.getElementById("x" + arr[i].id);     if(yes){       arr[i].style.display="block";       key.innerHTML="-";     }else{       arr[i].style.display="none";       key.innerHTML="+";     }   }}//--></script><div id='tree'><a id='xall' href="javascript:tog('all');">+</a><ul id='all' style="display:none;"><li>child1</li><li ><a id='xfather' href="javascript:tog('father');">+</a>father<ul id='father' style="display:none;"><li>child2</li><li>child3</li>  </ul></li></ul></div><p><a href="javascript:expall('tree',1);">Expand All</a> -- <a href="javascript:expall('tree',0);">Collapse All</a></p><p>Extended from <a href="http://www.codeproject.com/jscript/treemenu.asp">Marcelo Franco</a>'s tree menu.</p></body></html>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.