jQuery选择器练习

要求:

设置导航栏整体背景颜色为#cccccc

设置导航栏第一项默认背景颜色为#cccc73

设置二级菜单奇数行的背景颜色为#eec

设置菜单栏偶数行的背景颜色为#fcc00

 


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>导航下拉菜单</title>
    <script src="../lib/jquery.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .nav {
        width: 600px;
        margin: 80px auto;
        color: #333;
        border-radius: 6px;
        height: 50px;
        border: 1px solid #666;

        }

        .nav li {
            width: 140px;
            height: 50px;
            line-height: 50px;
            /* background: #17adf3; */
            float: left;
            text-align: center;
            /* margin-left: 10px; */
            cursor: pointer;
            _display: inline;
            position: relative;
        }

        li ul {
            position: absolute;
            left: 0;
            top: 50px;
            display: none;
        }
    </style>
</head>

<body>
    <ul class="nav">
        <li id="phone">
            <span>最热手机</span>
            <ul id="ul01">
                <li>小米10 pro</li>
                <li>华为 P40 Pro+</li>
                <li>三星S21 edge</li>
            </ul>
        </li>
        <li id="home">
            <span>家用商品</span>
            <ul id="ul02">
                <li>智能电饭煲</li>
                <li>微波炉</li>
                <li>电水壶</li>
            </ul>
        </li>
        <li id="outer">
            <span>户外产品</span>
            <ul id="ul03">
                <li>登山鞋</li>
                <li>冲锋衣</li>
                <li>智能手表</li>
            </ul>
        </li>
    </ul>

</body>

</html>

<script>
    function fn(canshu1, canshu2) {
        var li01 = document.getElementById(canshu1);
        var ul01 = document.getElementById(canshu2);

        li01.onmouseover = function () {
            ul01.style.display = "block"
        }
        li01.onmouseout = function () {
            ul01.style.display = "none"
        }
    }
    fn("phone", "ul01");
    fn("home", "ul02");
    fn("outer", "ul03");

    $(function (){
        $('ul').css('background-color','#cccccc');
        $('.nav>li').css('background-color','#cccc73');
        $('.nav ul>li:even').css('background-color','#eec');
        $('.nav ul>li:odd').css('background-color','#ffcc00');
    });

</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值