jquery 导航栏下拉菜单(折叠)在Bootstrap中不起作用[关闭]

kx1ctssn  于 2023-04-29  发布在  jQuery
关注(0)|答案(1)|浏览(107)

**已关闭。**此问题不符合Stack Overflow guidelines。目前不接受答复。

这个问题似乎不是关于在help center定义的范围内编程。
3天前关闭。
Improve this question
我的导航栏无法正常工作。我使用Bootstrap 5,并在HTML中包含了必要的CSS和JavaScript文件。然而,当我点击导航栏切换按钮时,什么也没有发生,下拉菜单也没有出现。我已经仔细检查了我的代码,它似乎与Bootstrap文档中的示例相匹配。谁能帮我找出问题的原因?

<nav class="navbar navbar-expand-xxl bg-dark navbar-dark py-3 justify-content-between justify-content-xxl-start">
  <div class="container container-fluid">
    <a class="navbar-brand" href="/vacancies/all">
      <img class="navbar-brand" src="/brunojobs.png" class="img-fluid" alt="brunojobs logo" height="45">
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
        <li class="nav-item">

 
         <a class="nav-link" href="/vacancies/all">Vagas</a>
        </li>
        <% unless company_signed_in? %>
          <li class="nav-item">
            <a class="nav-link" href="/companies/sign_up">Anunciar</a>
          </li>
        <% else %>
          <li class="nav-item">
            <a class="nav-link" href="/vacancies/new">Anunciar</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="/vacancies">Meus Anúncios</a>
          </li>
        <% end %>
      </ul>
      <ul class="navbar-nav ms-auto">
          <% if company_signed_in? %>
            <li class="nav-item">
              <a class="nav-link" href="/companies/edit">Meus Dados</a>
            </li>
            <li class="nav-item">
              <%= link_to('Sair', destroy_company_session_path, method: :delete, class: 'nav-link') %>
            </li>
          <% else %>
            <li class="nav-item">
                <a class="nav-link" href="/companies/sign_in">Entrar</a>
            </li>
          <% end %>
      </ul>
    </div>
  </div>
</nav>`

Vagas Anunciar Meus Anúncios Meus Dados Entrar

o8x7eapl

o8x7eapl1#

试试这个代码它的工作请检查(CSS,JS)CDN配置

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" >
  </head>
  <body>
    <nav class="navbar navbar-expand-xxl bg-dark navbar-dark py-3 justify-content-between justify-content-xxl-start">
        <div class="container container-fluid">
          <a class="navbar-brand" href="/vacancies/all">
            <img class="navbar-brand" src="/brunojobs.png" class="img-fluid" alt="brunojobs logo" height="45">
          </a>
          <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
          <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
              <li class="nav-item">
      
       
               <a class="nav-link" href="/vacancies/all">Vagas</a>
              </li>
              <% unless company_signed_in? %>
                <li class="nav-item">
                  <a class="nav-link" href="/companies/sign_up">Anunciar</a>
                </li>
              <% else %>
                <li class="nav-item">
                  <a class="nav-link" href="/vacancies/new">Anunciar</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="/vacancies">Meus Anúncios</a>
                </li>
              <% end %>
            </ul>
            <ul class="navbar-nav ms-auto">
                <% if company_signed_in? %>
                  <li class="nav-item">
                    <a class="nav-link" href="/companies/edit">Meus Dados</a>
                  </li>
                  <li class="nav-item">
                    <%= link_to('Sair', destroy_company_session_path, method: :delete, class: 'nav-link') %>
                  </li>
                <% else %>
                  <li class="nav-item">
                      <a class="nav-link" href="/companies/sign_in">Entrar</a>
                  </li>
                <% end %>
            </ul>
          </div>
        </div>
      </nav>`
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" ></script>
  </body>
</html>

相关问题