嘿伙计们,我正在研究一个使用bootstrap4的 django项目,而且我有一个问题就是下拉切换器…… 切换器仅在第二个链接后切换下拉菜单! 我做错了什么? 这是我的下拉HTML代码: li class="na
切换器仅在第二个链接后切换下拉菜单!
我做错了什么?
这是我的下拉HTML代码:
<li class="nav-item dropdown show"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Dropdown Toggler </a> <div class="dropdown-menu" role="menu" aria-labelledby="navbarDropdown"> <a class="dropdown-item">Link 1</a> <a class="dropdown-item">Link 2</a> </div> </li>你需要使用这样的切换,并将数据目标分配给下拉菜单中的id
运用
data-target=”#navbarDropdown”
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarDropdown" aria-controls="navbarDropdown" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button>然后将该ID分配给菜单
<li class="nav-item dropdown show"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarDropdown" aria-controls="navbarDropdown" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div id="navbarDropdown" class="dropdown-menu" role="menu" aria-labelledby="navbarDropdown"> <a class="dropdown-item">Link 1</a> <a class="dropdown-item">Link 2</a> </div> </li>