我试图使用引导程序通过数据属性创建下拉按钮,但是当我单击按钮时什么也没发生。
我遵循官方文档,甚至直接复制示例,但按钮未打开菜单。有测试页:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="/static/the_elder_commands/base.css" rel="stylesheet">
<title>Title</title>
</head>
<body>
<div class="btn-group dropright">
<button class="btn btn-dark dropdown-toggle" type="button" id="id_something"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Template
</button>
<div class="dropdown-menu" aria-labelledby="id_something">
<a class="dropdown-item" href="#">Template</a>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
</body>
</html>
有人可以告诉我缺少什么或做错什么吗?
答案 0 :(得分:1)
在Bootstrap的官方页面中,他们提到您必须先加载jquery,然后再加载pooper js,最后再加载他们的javascript,您输错了命令
他们的官方例子
>>> from functools import reduce
>>> from operator import xor
>>> bits = ('0', '1', '0', '1', '0', '1', '0')
>>> reduce(xor, map(int, bits))
1
如果您打算使用它,我建议您使用jQuery的缩小版本(而不是苗条)
答案 1 :(得分:0)
根据文档:
jQuery must come first, then Popper.js, and then our JavaScript plugins.
因此,您要做的就是更改script
标签的顺序。
像这样:
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
应该可以解决问题
答案 2 :(得分:0)
您以错误的顺序将脚本链接到了您的项目中,让我们修复一下:
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/smart/resources/business/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>ADMIN</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>open resource</web-resource-name>
<url-pattern>/smart/resources/registrations/*</url-pattern>
</web-resource-collection>
</security-constraint>
<security-role>
<role-name>ADMIN</role-name>
</security-role>
<security-role>
<role-name>USER</role-name>
</security-role>
您可以在这里进行测试:https://jsfiddle.net/26u0bax5/