<html>
<head>
<title>js实现的无限级树形下拉导航列表 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
    *{ margin:0; padding:0;    list-style:none;}
    body { margin:20px;}
    h2 { font-family:"黑体"; font-size:24px; text-align:center; line-height:32px;}
    h5 { font-size:12px; text-align:center; font-weight:normal; color:#666; line-height:28px;}
    #nav a { text-decoration:underline;color:#06c; font-size:14px; line-height:24px;}
    #nav ul{ margin-bottom:5px;}
    #nav strong{ color:#696;}
    #nav.dyn li ul{ display:none;}
    #nav.dyn li ul.show{ display:block;}
    #nav.dyn li{ padding-left:15px;}
    #nav.dyn li.parent{    background:url(user_23.gif) 5px 10px no-repeat;}
    #nav.dyn li.open{ background:url(user_23.gif) 5px -34px no-repeat;}
    </style>
</head>
<body>
<script type="text/javascript">
    DOMhelp = {
        debugWindowId: 'DOMhelpdebug',
        init: function () {
            if (!document.getElementById || !document.createTextNode) { return; }
        },
        lastSibling: function (node) {
            var tempObj = node.parentNode.lastChild;
            while (tempObj.nodeType != 1 && tempObj.previousSibling != null) {
                tempObj = tempObj.previousSibling;
            }
            return (tempObj.nodeType == 1) ? tempObj : false;
        },
        firstSibling: function (node) {
            var tempObj = node.parentNode.firstChild;
            while (tempObj.nodeType != 1 && tempObj.nextSibling != null) {
                tempObj = tempObj.nextSibling;
            }
            return (tempObj.nodeType == 1) ? tempObj : false;
        },
        getText: function (node) {
            if (!node.hasChildNodes()) { return false; }
            var reg = /^\s+$/;
            var tempObj = node.firstChild;
            while (tempObj.nodeType != 3 && tempObj.nextSibling != null || reg.test(tempObj.nodeValue)) {
                tempObj = tempObj.nextSibling;
            }
            return tempObj.nodeType == 3 ? tempObj.nodeValue : false;
        },
        setText: function (node, txt) {
            if (!node.hasChildNodes()) { return false; }
            var reg = /^\s+$/;
            var tempObj = node.firstChild;
            while (tempObj.nodeType != 3 && tempObj.nextSibling != null || reg.test(tempObj.nodeValue)) {
                tempObj = tempObj.nextSibling;
            }
            if (tempObj.nodeType == 3) { tempObj.nodeValue = txt } else { return false; }
        },
        createLink: function (to, txt) {
            var tempObj = document.createElement('a');
            tempObj.appendChild(document.createTextNode(txt));
            tempObj.setAttribute('href', to);
            return tempObj;
        },
        createTextElm: function (elm, txt) {
            var tempObj = document.createElement(elm);
            tempObj.appendChild(document.createTextNode(txt));
            return tempObj;
        },
        closestSibling: function (node, direction) {
            var tempObj;
            if (direction == -1 && node.previousSibling != null) {
                tempObj = node.previousSibling;
                while (tempObj.nodeType != 1 && tempObj.previousSibling != null) {
                    tempObj = tempObj.previousSibling;
                }
            } else if (direction == 1 && node.nextSibling != null) {
                tempObj = node.nextSibling;
                while (tempObj.nodeType != 1 && tempObj.nextSibling != null) {
                    tempObj = tempObj.nextSibling;
                }
            }
            return tempObj.nodeType == 1 ? tempObj : false;
        },
        initDebug: function () {
            if (DOMhelp.debug) { DOMhelp.stopDebug(); }
            DOMhelp.debug = document.createElement('div');
            DOMhelp.debug.setAttribute('id', DOMhelp.debugWindowId);
            document.body.insertBefore(DOMhelp.debug, document.body.firstChild);
        },
        setDebug: function (bug) {
            if (!DOMhelp.debug) { DOMhelp.initDebug(); }
            DOMhelp.debug.innerHTML += bug + '\n';
        },
        stopDebug: function () {
            if (DOMhelp.debug) {
                DOMhelp.debug.parentNode.removeChild(DOMhelp.debug);
                DOMhelp.debug = null;
            }
        },
        getKey: function (e) {
            if (window.event) {
                var key = window.event.keyCode;
            } else if (e) {
                var key = e.keyCode;
            }
            return key;
        },
        /* helper methods */
        getTarget: function (e) {
            var target = window.event ? window.event.srcElement : e ? e.target : null;
            if (!target) { return false; }
            while (target.nodeType != 1 && target.nodeName.toLowerCase() != 'body') {
                target = target.parentNode;
            }
            return target;
        },
        stopBubble: function (e) {
            if (window.event && window.event.cancelBubble) {
                window.event.cancelBubble = true;
            }
            if (e && e.stopPropagation) {
                e.stopPropagation();
            }
        },
        stopDefault: function (e) {
            if (window.event && window.event.returnValue) {
                window.event.returnValue = false;
            }
            if (e && e.preventDefault) {
                e.preventDefault();
            }
        },
        cancelClick: function (e) {
            if (window.event) {
                window.event.cancelBubble = true;
                window.event.returnValue = false;
            }
            if (e && e.stopPropagation && e.preventDefault) {
                e.stopPropagation();
                e.preventDefault();
            }
        },
        addEvent: function (elm, evType, fn, useCapture) {
            if (elm.addEventListener) {
                elm.addEventListener(evType, fn, useCapture);
                return true;
            } else if (elm.attachEvent) {
                var r = elm.attachEvent('on' + evType, fn);
                return r;
            } else {
                elm['on' + evType] = fn;
            }
        },
        cssjs: function (a, o, c1, c2) {
            switch (a) {
                case 'swap':
                    o.className = !DOMhelp.cssjs('check', o, c1) ? o.className.replace(c2, c1) : o.className.replace(c1, c2);
                    break;
                case 'add':
                    if (!DOMhelp.cssjs('check', o, c1)) { o.className += o.className ? ' ' + c1 : c1; }
                    break;
                case 'remove':
                    var rep = o.className.match(' ' + c1) ? ' ' + c1 : c1;
                    o.className = o.className.replace(rep, '');
                    break;
                case 'check':
                    var found = false;
                    var temparray = o.className.split(' ');
                    for (var i = 0; i < temparray.length; i++) {
                        if (temparray[i] == c1) { found = true; }
                    }
                    return found;
                    break;
            }
        },
        safariClickFix: function () {
            return false;
        }
    }
    DOMhelp.addEvent(window, 'load', DOMhelp.init, false);
</script>
<script type="text/javascript">
<!--
    sn = {
        dynamicClass: 'dyn',
        showClass: 'show',
        parentClass: 'parent',
        openClass: 'open',
        navID: 'nav',
        init: function () {
            var triggerLink;
            if (!document.getElementById || !document.createTextNode) { return; }
            var nav = document.getElementById(sn.navID);
            if (!nav) { return; }
            DOMhelp.cssjs('add', nav, sn.dynamicClass);
            var nested = nav.getElementsByTagName('ul');
            for (var i = 0; i < nested.length; i++) {
                triggerLink = nested[i].parentNode.getElementsByTagName('a')[0];
                DOMhelp.cssjs('add', triggerLink.parentNode, sn.parentClass);
                DOMhelp.addEvent(triggerLink, 'click', sn.changeSection, false);
                triggerLink.onclick = DOMhelp.safariClickFix;
                if (nested[i].parentNode.getElementsByTagName('strong').length > 0) {
                    DOMhelp.cssjs('add', triggerLink.parentNode, sn.openClass);
                    DOMhelp.cssjs('add', nested[i], sn.showClass);
                }
            }
        },
        changeSection: function (e) {
            var t = DOMhelp.getTarget(e);
            var firstList = t.parentNode.getElementsByTagName('ul')[0];
            if (DOMhelp.cssjs('check', firstList, sn.showClass)) {
                DOMhelp.cssjs('remove', firstList, sn.showClass)
                DOMhelp.cssjs('swap', t.parentNode, sn.openClass, sn.parentClass);
            } else {
                DOMhelp.cssjs('add', firstList, sn.showClass)
                DOMhelp.cssjs('swap', t.parentNode, sn.openClass, sn.parentClass);
            }
            DOMhelp.cancelClick(e);
        }
    }
    DOMhelp.addEvent(window, 'load', sn.init, false);
-->
</script>
<h2>js实现无限级树形导航列表</h2>
<ul id="nav">
   
    <li><a href="#">产品目录</a>
        <ul>
            <li><a href="#">大类别一</a>
                <ul>
                    <li><a href="#">小类别一</a>
                        <ul>
                            <li><a href="#">次类别一</a></li>
                            <li><a href="#">次类别二</a></li>
                        </ul>
                    </li>
                    <li><a href="#">小类别二</a></li>
                </ul>
            </li>
            <li><a href="#">大类别二</a></li>
            <li><a href="#">大类别三</a>
                <ul>
                    <li><a href="#">小类别一</a></li>
                    <li><a href="#">小类别二</a></li>
                </ul>
            </li>
        </ul>
    </li>
    <li><a href="#">服务</a>
        <ul>
            <li><a href="#">大类别一</a>
               <ul>
                    <li><a href="#">小类别一</a></li>
                    <li><a href="#">小类别二</a></li>
                </ul>
            </li>
            <li><a href="#">大类别二</a>
                 <ul>
                    <li><a href="#">小类别一</a></li>
                    <li><a href="#">小类别二</a></li>
                </ul>
            </li>
            <li><a href="#">大类别三</a>
                 <ul>
                    <li><a href="#">小类别一</a></li>
                    <li><a href="#">小类别二</a></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>
</body>
</html>

js实现无限级树形导航列表的更多相关文章

  1. 实用js+css多级树形展开效果导航菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. SharePoint2010沙盒解决方案基础开发——关于TreeView树形控件读取列表数据(树形导航)的webpart开发及问题

    转:http://blog.csdn.net/miragesky2049/article/details/7204882 SharePoint2010沙盒解决方案基础开发--关于TreeView树形控 ...

  3. vue 无限级分类导航

    递归组件,实现无限级分类导航 https://cn.vuejs.org/v2/guide/components-edge-cases.html#%E9%80%92%E5%BD%92%E7%BB%84% ...

  4. ExtPB.Net:窗体应用技巧(2)在树形导航下打开弹出的win窗口

    ExtPB.Net的demo程序有个树形导航菜单,里面的菜单打开的窗口放在右边的TabStrip控件中.我们可以设计win通过导航打开,但有时我们希望以弹出窗口的形式打开它,但怎么办呢?现在可以这样修 ...

  5. 在ASP.NET MVC下实现树形导航菜单

    在需要处理很多分类以及导航的时候,树形导航菜单就比较适合.例如在汽车之家上: 页面主要分两部分,左边是导航菜单,右边显示对应的内容.现在,我们就在ASP.NET MVC 4 下临摹一个,如下: 实现的 ...

  6. JQUERY实现的小巧简洁的无限级树形菜单

    JQUERY实现的小巧简洁的无限级树形菜单,可用于后台或前台侧栏菜单!兼容性也比较好. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tra ...

  7. css+js实现自动伸缩导航栏

    用css+js实现自动伸缩导航栏 需要达到的效果: 默认首页选中样式 设置鼠标滑过效果:颜色变化(#f60),宽度变化,字体变化 所涉及的知识点: 布局:float css: 元素状态切换(displ ...

  8. ASP.NET的面包屑导航控件、树形导航控件、菜单控件

    原文:http://blog.csdn.net/pan_junbiao/article/details/8579293 ASP.NET的面包屑导航控件.树形导航控件.菜单控件. 1. 面包屑导航控件— ...

  9. QT QML目录导航列表视图

    [功能] /目录.文件 /文件过滤 /递归 /事件 /高亮当前行 /当前选项 /目录切换动画 /限制根目录 [下载]:http://download.csdn.net/detail/surfsky/8 ...

随机推荐

  1. LeetCode Backpack

    Given n items with size Ai, an integer m denotes the size of a backpack. How full you can fill this ...

  2. C++知识点整理——持续更新

    virtual是C++的一个关键字,virtual修饰的函数可以被子类重写.   用法:在返回值类型的前面添加关键字即可. override是C++的保留字(注意不是关键字),表示当前函数重写了基类的 ...

  3. ADO接口

    转自百度文库 ADO中最重要的对象有三个:Connection.Recordset和Command,分别表示连接对象.记录集对象和命令对象. 三个对象对应的智能指针分别是:_ConnectionPtr ...

  4. GBK转utf-8,宽字符转窄字符

    //GBK转UTF8 string CAppString::GBKToUTF8(const string & strGBK) { string strOutUTF8 = "" ...

  5. 5.6.1 Boolean类型

    Boolean类型是与布尔值对应的引用类型.要创建Boolean对象,可以像下面这样调用Boolean构造函数并传入true或false值. var booleanObject=new Boolean ...

  6. DM368 arm板GDB远程调试

    参考: http://www.erchashu.com/wiki/eclipse-cdt-gdb-arm-app-cross-debug 远程调试环境由宿主机GDB和目标机调试stub共同构成,两者通 ...

  7. 堆排序(java实现)

    public class Test04 { static int a[] = {9,8,7,6,5,4,3,2,1,11,12,10,19,18,17,16}; public static void ...

  8. 帝国cms数据表详细说明

    表 名 解释 phome_ecms_infoclass_news 新闻采集规则记录表 phome_ecms_infotmp_news 采集临时表 phome_ecms_news 新闻主数据记录表 ph ...

  9. JavaScript中的鼠标滚轮事件详解

    JavaScript中的鼠标滚轮事件详解/*Firefox注册事件*/ ~~~Firefox: addEventListener('DOMMouseScroll', handler, false)if ...

  10. tcpdump抓包并保存成cap文件

    首选介绍一下tcpdump的常用参数 tcpdump采用命令行方式,它的命令格式为: tcpdump [ -adeflnNOpqStvx ] [ -c 数量 ] [ -F 文件名 ] [ -i 网络接 ...