为什么这个Bootstrap导航栏的切换按钮不起作用?

2hh7jdfx  于 2023-11-15  发布在  Bootstrap
关注(0)|答案(3)|浏览(111)

我正在尝试创建引导导航栏,但切换按钮不起作用。我使用了class .sidebar-collapse on body标记,因此当我单击切换按钮时,数据应该出现在右侧。但这并没有发生。有人能告诉我我的代码有什么问题吗?

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/core.js"> 
</script>
<meta charset="utf-8">
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="css/now-ui-kit.css" type="text/css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font- 
awesome.min.css" rel="stylesheet" integrity="sha384- 
wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" 
crossorigin="anonymous">
<title>
    Techversity
</title>
</head>
<body class="sidebar-collapse">
<nav class="navbar navbar-expand-lg bg-primary">
<div class="container">
    <div class="navbar-translate">
        <a class="navbar-brand" href="#pablo">
           Techversity
       </a>
        <button class="navbar-toggler navbar-toggler-right" type="button" 
data-toggle="collapse" data-target="#navigation" aria-controls="navigation- 
index" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-bar bar1"></span>
        <span class="navbar-toggler-bar bar2"></span>
        <span class="navbar-toggler-bar bar3"></span>
    </button>

    </div>

    <div class="collapse navbar-collapse justify-content-end" 
 id="navigation">
        <ul class="navbar-nav">
            <li class="nav-item active">
                <a class="nav-link" href="#pablo">
                    Home
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#pablo">Link</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#pablo">Disabled</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#pablo"><i class="fa fa-instagram" 
aria-hidden="true"></i></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#pablo"><i class="fa fa-youtube- 
play" aria-hidden="true"></i></a>
            </li>
        </ul>
    </div>
</div>
</nav>
</body>
</html>

字符串

gj3fmq9x

gj3fmq9x1#

标记不正确。在nav.navbar元素中不应该有div.containerdiv.navbar-translate元素。我在没有它们的情况下tried它并且它工作。此外,您可以在这里检查标记不是Bootstrap所期望的标记。

cxfofazt

cxfofazt3#

经过几个小时的挣扎,我才意识到Bootstrap Toggle不工作的可能性:

  1. jquery.min.js尚未导入html文件
  2. jquery.min.js已被导入,但它被放置在header标记中,而不是body标记的底部。

相关问题