html - 使用 bootstrap 4 时,bootstrap 下拉按钮不会下拉
问题描述
我正在使用引导程序创建一个烧瓶应用程序。我正在尝试使用需要 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>
作为参考,这是我的文件树的样子
这些是我安装的依赖项的版本(使用 yarn 安装)
- @popperjs/core@2.4.4
- 引导@4.5.2
- jquery@3.3.1
- popper.js@1.16.1
控制台中没有显示错误消息
当我像这样引用脚本时,我没有任何问题
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>
我已经看到了很多相关的问题,但是到目前为止所建议的解决方案都没有奏效。这是我迄今为止看到的建议:
- 确保 jquery 脚本出现在引导脚本之前(检查)
- 删除 popper 依赖并使用 bootstrap.bundle.js 或 bootstrap.bundle.min.js (我都试过了)
- 确保您没有两次包含引导 jquery(检查)
- 添加
<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>
推荐阅读
- r - 与 {highcharter} 等效的 highcharts 地图
- open-liberty - webprofile 6 在 openliberty 中丢失,但在 websphere liberty 中没有
- c# - 如何从 C# 文件中读取 16 位数字?
- react-native - 仅调用 1 次的反应本机 fetch
- c# - EF Core 3.1 中间投影 VS 迭代结果以设置附加属性
- python-3.x - 你如何在 Python3 中设置 cookie 策略?
- python - 亚马逊登录和访问订单
- reactjs - 使用 react js 发布项目
- git - Git更新被拒绝,因为尽管在克隆后做了它,但分支的尖端落后了?
- azure - 有没有办法将发布管道数据发送到 devops 中的 GIT 存储库?