JavaScript Static Tree Menu Implementation code _ navigation menu

Source: Internet
Author: User
Who is interested can be changed to dynamic loading data, or with jquery, the code will certainly be much less! I found that adding some CSS, this tree on the static page is still very useful!
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <style type=" Text/css ">. expand{cursor:po Inter }. hide{Cursor:pointer; } </style> <script type= "Text/javascript" > Function Togglechild (o) {var cls = O.getattribute ("class"); if (CLS = = "expand") {var sb = o.nextsibling; if (window.innerwidth) sb = sb.nextsibling; while (SB!= null && sb.tagName.toLowerCase () = = ' dd ') {sb.style.display = ' none '; SB = sb.nextsibling; if (window.innerwidth) sb = sb.nextsibling; } o.removeattribute ("class"); O.setattribute ("Class", "Hide"); if (window.innerwidth)//ff o.textcontent = "Field" + o.textcontent.substring (1); else O.innertext = "Tian" + o.innertext.substring (1); else {var sb = o.nextsibling; if (window.innerwidth) sb = sb.nextsibling; while (SB!= null && sb.tagName.toLowerCase () = = ' dd ') {sb.style.display = ""; SB = sb.nextsibling; if (window.innerwidth) sb = sb.nextsibling; } o.removeattribute ("class"); O.setattribute ("Class", "expand"); if (window.innerwidth)//ff o.textcontent = "Yue" + o.textcontent.substring (1); else O.innertext = "Yue" + o.innertext.substring (1); } function Maketree (obj) {var DTS = obj.getelementsbytagname (' dt '); for (var i = 0; i < dts.length i++) {Dts[i].setattribute ("Class", "expand"); if (window.innerwidth)//ff dts[i].textcontent = "Yue" + dts[i].textcontent; else Dts[i].innertext = "Yue" + dts[i].innertext; Dts[i].onclick = function () {togglechild (this); } window.onload = function () {Maketree (document.getElementById ("tree")); }; </script> </pead> <body> <p> definition list can also become a tree:</p> <dl id= "Trees" > <dt> menu 1</ dt> <dd>1.1 aaa</dd> <dd>1.2 bbb</dd> <dd>1.3 <dt> Menu ccc</dd> ; <dd>2.1 Hello </dd><dd> Hyperlinks </dd> <dt> menus 3</dt> <dd> <dl > <dt>3.1</dt> <dd> Baidu News < /dd> <dd> Sohu News </dd> <dt>3.2</dt> <dd> Baidu News </dd> <dd> Sohu News </dd> < /dl> </dd> </dl> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.