zoukankan      html  css  js  c++  java
  • 联级菜单

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    </head>
    <body>
    <ul>
    <li>一级菜单ITEM
    <ul>
    <li>二级菜单</li>
    <li>二级菜单</li>
    <li>二级菜单</li>
    <li>二级菜单ITEM
    <ul>
    <li>三级菜单</li>
    <li>三级菜单</li>
    <li>三级菜单</li>
    <li>三级菜单
                                <ul>
                                    <li>四级菜单</li>
                                    <li>四级菜单</li>
                                    <li>四级菜单</li>
                                    <li>四级菜单</li>
                                </ul>
                            </li>
    </ul>
    </li>
    </ul>
    </li>
    <li>一级菜单</li>
    <li>一级菜单ITEM
    <ul>
    <li>二级菜单</li>
    <li>二级菜单</li>
    <li>二级菜单</li>
    <li>二级菜单ITEM
    <ul>
    <li>三级菜单</li>
    <li>三级菜单</li>
    <li>三级菜单</li>
    <li>三级菜单</li>
    </ul>
    </li>
    </ul>
    </li>
    <li>一级菜单</li>
    </ul>
    </body>
    </html>
    <script>
        var list = document.getElementsByTagName("li");//获取所有li
        //为每个li添加点击事件,判断是否有子元素
        for(var i = 0; i < list.length; i++){
            list[i].onclick = function(e){
                var e = e || event;
                e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true;
                //li如果有子元素
                if(this.children[0]){
                    if(this.children[0].style.display == "none"){
                        this.children[0].style.display = "block";
                    }else{
                        this.children[0].style.display = "none";
                    }
                }
            }
        }
    </script>
  • 相关阅读:
    添加Google Admob到ANDROID应用中
    linux命令及实例说明一:cd、ls、rmdir、rm、mkdir
    android中dip、dp、px、sp和屏幕密度
    在程序中读取ANDROID应用的程序名称和版本号
    linux常用命令及实例二:cp、mv、chown、chmod、find
    Android开发,常用的终端命令
    eclipse里配置solr开发测试环境
    自定义Dialog之Progress(二)
    android 判断网络状态
    hive cli命令行选项
  • 原文地址:https://www.cnblogs.com/tis100204/p/10328760.html
Copyright © 2011-2022 走看看