【发布时间】:2020-12-02 18:54:07
【问题描述】:
我正在使用引导程序创建一个烧瓶应用程序。我正在尝试使用需要 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
- bootstrap@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>(无效)
【问题讨论】:
标签: html jquery bootstrap-4 drop-down-menu popper.js