小编Ven*_*hav的帖子

如何在纯JavaScript中为元素添加和删除活动类

我试图制作一个导航菜单我做了所有的HTMLCSS时来到javascript我在中间被击中我能够添加一个类的元素,但我无法删除类剩余的元素.请帮我解决一下这个.
这是我的代码

<!DOCTYPE html>
    <html>
    <head>
        <title>Navigation class Toggling</title>

        <style type="text/css">
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        header {
            width: 100%;
            height: auto;
            max-width: 600px;
            margin: 0 auto;
        }
        nav {
            width: 100%;
            height: 40px;
            background-color: cornflowerblue;
        }
        ul {
            list-style-type: none;
        }
        li {
            display: inline-block;
        }
        a {
            text-decoration: none;
            padding: 8px 15px;
            display: block;
            text-transform: capitalize;
            background-color: darkgray;
            color: #fff;
        }
        a.active {
            background-color: cornflowerblue;
        }
        </style>
    </head> …
Run Code Online (Sandbox Code Playgroud)

html javascript css

5
推荐指数
3
解决办法
3万
查看次数

标签 统计

css ×1

html ×1

javascript ×1