[英]My dropdown is not working using bootstrap
I create a dropdown which is the drop down will be triggered by a button from the search bar and underneath the search bar the drop down content will be deploy.我创建了一个下拉列表,该下拉列表将由搜索栏上的按钮触发,在搜索栏下方将部署下拉内容。 Though my code wont work
虽然我的代码不起作用
<div class="col-8">
<div class="input-group mb-3">
<div class="input-group-prepend" id="button-addon3">
<div class="dropdown">
<button class="btn btn-outline-secondary " type="button" style="color:black;background-color: darkcyan">Search</button>
<div id="myDropdown" class="dropdown-content">
<a href="#home">Home</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
</div>
</div>
<button class="btn btn-outline-secondary" type="button" style="color:black;background-color: darkcyan" onCLick="myFunction()">Filter</button>
</div>
<input type="text" class="form-control" placeholder="Search Reports Here" aria-label="Example text with two button addons" aria-describedby="button-addon3">
</div>
</div>
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
Hi if you are using bootstrap you can make use of bootstrap dropdown itself please kindly use the below code no need of writing script as well in this.嗨,如果您使用引导程序,您可以使用引导程序下拉本身,请使用以下代码,无需在此编写脚本。 :)
:)
<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</button>
<div class="dropdown-menu">
<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 role="separator" class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
<button class="btn btn-outline-secondary" type="button">Filter</button>
</div>
<input type="text" class="form-control" aria-label="Text input with dropdown button">
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.