我想在不使用jquery
的情况下创建bootstrap下拉列表<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</div>
请帮助如何做到这一点
答案 0 :(得分:1)
我写了我的Dropdown菜单脚本,没有Jquery,没有Bootstrap js,只有Bootstrap CSS,无论如何都很容易覆盖:
document.addEventListener('DOMContentLoaded', function () {
// -----Dropdown----------
// Rule: link.dropdown-link data-dropdown='dropdownIdentifier' div#dropdownIdentifier
let dropdowns = document.querySelectorAll('.dropdown-link');
for (dropdown of dropdowns) {
dropdown.onclick = function (e) {
let dropdownDiv = document.getElementById(dropdown.getAttribute('data-dropdown'))
if (dropdownDiv.style.display == "block") {
dropdownDiv.style.display = "none";
} else {
dropdownDiv.style.display = "block";
}
}
}
});
现在使用html:
<a class="dropdown-link" data-dropdown="dropdownId">Prodbox</a>
<div id="dropdownId" class="dropdown-menu">
1
2
3
</div>
请注意,dropdown-menu是引导类的样式,如果您不使用引导CSS,则可以编写自己的
答案 1 :(得分:0)
Rememebr将ui-bootstrap指令添加到angular.module
Html代码
<ul uib-dropdown-menu role="menu" aria-labelledby="btn-append-to-body">
<li role="menuitem"><a href="#">Action</a></li>
<li role="menuitem"><a href="#">Another action</a></li>
<li role="menuitem"><a href="#">Something else here</a></li>
<li class="divider"></li>
<li role="menuitem"><a href="#">Separated link</a></li>
</ul>
Js Code
angular.module('ui.bootstrap.demo').controller('DropdownCtrl', function ($scope, $log) {
$scope.items = [
'The first choice!',
'And another choice for you.',
'but wait! A third!'
];
$scope.status = {
isopen: false
};
$scope.toggled = function(open) {
$log.log('Dropdown is now: ', open);
};
$scope.toggleDropdown = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.status.isopen = !$scope.status.isopen;
};
$scope.appendToEl = angular.element(document.querySelector('#dropdown-long- content'));
});