我在我的网站上使用Bootstrap。我正在尝试添加下拉列表的链接,它在桌面浏览器上运行良好。但不是在移动设备上工作。我该如何解决这些问题? 这是我的代码:
<nav id="navbar-primary" class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-primary-collapse">
<span class="sr-only">Mobile</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="collapse navbar-collapse" id="navbar-primary-collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="dropdownlink.html" class="dropdown-toggle disabled" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">DROPDOWN<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="link1.html">LINK 1</a></li>
<li><a href="link2.html">LINK 2</a></li>
</ul>
</li>
</ul>
</div>
</nav>
HOVER打开下拉菜单代码为:
$(function(){
$('.dropdown').hover(function() {
$(this).addClass('open');
},
function() {
$(this).removeClass('open');
});
});
因此,当我在移动设备上点击DROPDOWN时,浏览器将转到dropdownlink.html并且菜单未打开。我该如何解决?
答案 0 :(得分:0)
@media screen and (min-width: 768px) {
ul.nav li.dropdown:hover > ul.dropdown-menu {
display: block;
}
}
@media screen and (max-width: 768px) {
ul.nav li.dropdown.open > ul.dropdown-menu {
display: block;
}
ul.nav li.dropdown > ul.dropdown-menu {
display: none;
}
}