jQuery+HTML左侧导航栏,点击显示隐藏二级菜单(每日解决一题)

在今天写前端页面时,发现要用二级菜单,通过查找发现这个案例也许可以帮助你解决二级菜单的问题。

 HTML代码

 <div class="left">
        <ul>
            <li class="left1" style="border-top: 1px solid #ccc;border-bottom: 1px solid #ccc;">哈哈哈</li>
            <li class="left1" id="one" style="border-bottom: 1px solid #ccc;">知识
                <ul class="two">
                    <li>知识1</li>
                    <li>知识2</li>
                    <li>知识3</li>
                </ul>
            </li>
            <li class="left1" id="three" style="border-bottom: 1px solid #ccc;">1
                <ul class="four">
                    <li><a href="index.html">11</a></li>
                    <li>22</li>
                    <li>33</li>
                </ul>
            </li>
        </ul>
    </div>

CSS代码

 <style>
        .left {
            width: 240px;
            height: 240px;
            float: left;
        }

        .left1 {
            width: 100%;
            font-size: 16px;
            list-style: none;
            float: left;
            padding-bottom: 20px;
            padding-top: 20px;
        }

        .two {
            display: none;
            list-style: none;
        }

        .four {
            display: none;
            list-style: none;

        }
    </style>

JS代码

<script>
    $(function () {
        $("#one").on("click", function () {
            $(this).children(".two").toggle(1);
        });
    })
    $(function () {
        $("#three").on("click", function () {
            $(this).children(".four").toggle(1);
        });
    })
</script>

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值