bootstrap下拉按钮不使用bootstrap 4下拉

问题描述

我正在使用引导程序创建flask应用程序。我正在尝试使用需要jquery + popper的元素,例如下拉菜单。该按钮显示出来,但没有下拉

<!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="/static/node_modules/bootstrap/dist/css/bootstrap.min.css">

    <title>hello world</title>
  </head>

   <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>

    <script src="/static/node_modules/jquery/dist/jquery.min.js"</script>
    <script src="/static/node_modules/popper.js/dist/popper.min.js" </script>
    <script src="/static/node_modules/bootstrap/dist/js/bootstrap.min.js" </script>
  <body>
</html>

作为参考,这是我的文件树的样子

enter image description here

这些是我已经安装(使用yarn安装的)依赖项的版本

  1. @ popperjs / core @ 2.4.4
  2. [email protected]
  3. [email protected]
  4. [email protected]

控制台中没有显示错误消息

当我只引用这样的脚本时,我没有任何问题

https://getbootstrap.com/docs/4.1/getting-started/introduction/

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvcwpIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnjsK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>

我已经看到了许多有关问题的 ,但是到目前为止,所提出的解决方案都没有奏效。到目前为止,这是我所看到的建议:

  1. 确保jquery脚本位于引导脚本之前(检查)
  2. 删除popper依赖项并使用bootstrap.bundle.js或bootstrap.bundle.min.js(我都尝试过)
  3. 确保您没有两次包含引导jquery(选中)
  4. 添加<script>$('.dropdown-toggle').dropdown();</script>(无效)

解决方法

您忘记关闭index.html中的脚本标签

<script src="/static/node_modules/jquery/dist/jquery.min.js"></script>
<script src="/static/node_modules/popper.js/dist/popper.min.js"></script>
<script src="/static/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>