水平导航-js二级菜单方法一

Posted 启杰行者

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了水平导航-js二级菜单方法一相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>水平导航-二级菜单</title>
    <style type="text/css">
        *{
            padding:0px;
            margin: 0px;
        }
        .navBar{
            height: 30px;
            background-color: #2B383E;
            text-align: center;
        }
        ul{
            list-style: none;
        }
        .nav li{
            float: left;
        
        }
        .nav li a{
            display: block;
            padding: 0 20px;
            height: 30px;
            line-height: 30px;
            text-decoration: none;
            color: #fff;
        }
        .nav li a:hover{
            background-color: #fff;
            color: #4DB6E7
        }
        .TabMenuCon{
            clear: both;
            display: none;
        }
        .TabMenuCon li{
            display: inline-block;
        }
    </style>
    <script type="text/javascript">
        function selectTabMenu(i){
            switch(i){
           case 71:     
                document.getElementById("TabMenuCon71").style.display="block";
                document.getElementById("TabMenuCon72").style.display="none";
                 document.getElementById("TabMenuCon73").style.display="none";
                document.getElementById("TabMenuCon74").style.display="none";
                document.getElementById("TabMenuCon75").style.display="none";
                document.getElementById("TabMenuCon76").style.display="none";
                break;
            case 72:
                document.getElementById("TabMenuCon71").style.display="none";
                document.getElementById("TabMenuCon72").style.display="block";
                document.getElementById("TabMenuCon73").style.display="none";
                document.getElementById("TabMenuCon74").style.display="none";
                document.getElementById("TabMenuCon75").style.display="none";
                document.getElementById("TabMenuCon76").style.display="none";
                break;
            case 73:    
                document.getElementById("TabMenuCon71").style.display="none";
                document.getElementById("TabMenuCon72").style.display="none";
                document.getElementById("TabMenuCon73").style.display="block";
                document.getElementById("TabMenuCon74").style.display="none";
                document.getElementById("TabMenuCon75").style.display="none";
                document.getElementById("TabMenuCon76").style.display="none";
                break;
            case 74:
                document.getElementById("TabMenuCon71").style.display="none";
                document.getElementById("TabMenuCon72").style.display="none";
                document.getElementById("TabMenuCon73").style.display="none";
                document.getElementById("TabMenuCon74").style.display="block";
                document.getElementById("TabMenuCon75").style.display="none";
                document.getElementById("TabMenuCon76").style.display="none";
                break; 
            case 75:
                document.getElementById("TabMenuCon71").style.display="none";
                document.getElementById("TabMenuCon72").style.display="none";
                document.getElementById("TabMenuCon73").style.display="none";
                document.getElementById("TabMenuCon74").style.display="none";
                document.getElementById("TabMenuCon75").style.display="block";
                document.getElementById("TabMenuCon76").style.display="none";
                break; 
                case 76:
                document.getElementById("TabMenuCon71").style.display="none";
                document.getElementById("TabMenuCon72").style.display="none";
                document.getElementById("TabMenuCon73").style.display="none";
                document.getElementById("TabMenuCon74").style.display="none";
                document.getElementById("TabMenuCon75").style.display="none";
                document.getElementById("TabMenuCon76").style.display="block";
                break; 
           }
        }
    </script>
</head>
<body>
    <div class="navBar">
        <ul class="nav">
            <li><a href="#" onmouseover="selectTabMenu(71)">首页</a></li>
            <li><a href="#" onmouseover="selectTabMenu(72)">关于协会</a></li>
            <li><a href="#" onmouseover="selectTabMenu(73)">协会动态</a></li>
            <li><a href="#" onmouseover="selectTabMenu(74)">协会活动</a></li>
            <li><a href="#" onmouseover="selectTabMenu(75)">会员</a></li>
            <li><a href="#" onmouseover="selectTabMenu(76)">资源空间</a></li>
        </ul>
        
    </div>
    <div id="TabMenuCon">
        <ul id="TabMenuCon71" class="TabMenuCon">
            <li>公告</li>
            <li>信息</li>
        </ul>
        <ul id="TabMenuCon72" class="TabMenuCon">
            <li>协会简介</li>
            <li>组织机构</li>
            <li>协会章程</li>
        </ul>
        <ul id="TabMenuCon73" class="TabMenuCon">
            <li>协会新闻</li>
            <li>活动预告</li>
            <li>求职招聘</li>
        </ul>
        <ul id="TabMenuCon74" class="TabMenuCon">
            <li>义务维修月</li>
            <li>平面设计活动</li>
            <li>程序设计活动</li>
            <li>户外拓展</li>
        </ul>
        <ul id="TabMenuCon75" class="TabMenuCon">
            <li>会员登录</li>
            <li>会员注册</li>
            <li>缴纳会费</li>
            <li>会员信息管理</li>
            <li>修改密码</li>
        </ul>
        <ul id="TabMenuCon76" class="TabMenuCon">
            <li>PS教程</li>
            <li>前端设计</li>
            <li>Flash教程</li>
        </ul>
    </div>
    
</body>
</html>

 

以上是关于水平导航-js二级菜单方法一的主要内容,如果未能解决你的问题,请参考以下文章

怎么用vue.js实现一个二级导航栏

用原生JS实现的一个导航下拉菜单,下拉菜单的宽度与浏览器视口的宽度一样(js+html+css)

二级菜单打开后页面刷新不收缩效果

CSS3 二级导航菜单的制作的示例

html css 求助大神:导航栏菜单问题,二级菜单内容会遮盖掉后面的一级菜单栏选项。

织梦一二级导航菜单被点击顶级栏目高亮(加class)解决方法