我已经设置了我的代码,以便在打开Bootstrap菜单时运行警报,但我正在努力让警报响起。
$('.dropdown.data-api').on('shown.bs.dropdown', function () {
alert('it worked!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="dropdown">
<span data-toggle="dropdown">Click me</span>
<ul class="dropdown-menu">
<li>Hello World!
</ul>
</div>
答案 0 :(得分:1)
事件选择器正在查找包含dropdown
和data-api
类的下拉列表。从事件选择器中删除.data-api
,或将data-api
添加到下拉类列表中。
$('.dropdown.data-api').on('shown.bs.dropdown', function () {
alert('it worked!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="dropdown data-api">
<span data-toggle="dropdown">Click me</span>
<ul class="dropdown-menu">
<li>Hello World!
</ul>
</div>