簡體   English   中英

Bootstrap 下拉菜單不起作用 - 如何修復?

[英]Bootstrap dropdown not working — how to fix?

我看過其他類似的問題,但它們都不起作用。 我正在使用 Django,這是我的代碼。

index.html

{% extends 'base.html' %}
{% block body %}
    <nav>
        <div class="logo">
            Cleaveway Pizzas
        </div>
        <ul class="nav-links">
            <li><a href="#">1</a></li>
            <li><a href="#">2</a></li>
            <li><a href="#">3</a></li>
        </ul>
        <div class="dropdown">
            <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Dropdown button
            </button>
            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
                <a class="dropdown-item" href="#">Action</a>
                <a class="dropdown-item" href="#">Another action</a>
                <a class="dropdown-item" href="#">Something else here</a>
            </div>
        </div>
    </nav>
{% endblock %}

base.html

{% load static %}
<html lang="en">
<head>
    <title>{% block title %}{% endblock %}</title>
    <link rel="stylesheet" href="{% static 'bootstrap/bootstrap.min.css' %}">
    <link rel="stylesheet" href="{% static 'bootstrap/bootstrap-grid.min.css' %}">
    <link rel="stylesheet" href="{% static 'bootstrap/bootstrap-reboot.min.css' %}">
    <link rel="stylesheet" href="{% static 'pizza/login.css' %}">
    <link rel="stylesheet" href="{% static 'pizza/navbar.css' %}">
    <link rel="stylesheet" href="{% static 'import/import.css' %}">
    <link rel="script" href="{% static 'bootstrap/bootstrap.bundle.js' %}">
    <link rel="script" href="{% static 'bootstrap/bootstrap.js' %}">
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>

誰能幫忙? 它顯示按鈕,但單擊按鈕時沒有任何反應。

代替

<link rel="script" href="{% static 'bootstrap/bootstrap.bundle.js' %}">
<link rel="script" href="{% static 'bootstrap/bootstrap.js' %}">

經過:

<script src="{% static 'bootstrap/bootstrap.bundle.js' %}" type="text/javascript"></script>
<script src="{% static 'bootstrap/bootstrap.js' %}" type="text/javascript"></script>

根據引導文檔嘗試使用適當的腳本。

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
  </body>
</html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM