gpt4 book ai didi

javascript - 带有子菜单的 Bootstrap 导航栏 - 如何删除 768 下的类 "disabled"@media width

转载 作者:太空宇宙 更新时间:2023-11-03 22:46:31 24 4
gpt4 key购买 nike

我已经使用“disabled”类来激活主菜单上的链接。但是我怎样才能删除媒体宽度 768 上的“禁用”类?或者如何在小屏幕上禁用“禁用”类功能? (不需要“主菜单 1”上的链接@768)

if ($(window).width() > 768) {
$('ul.nav li.dropdown').hover(function () {
$(this).find('.dropdown-menu').stop(true, true).delay(600).fadeIn(200);
}, function () {
$(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(600);
});
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css">



<div class="container">
<nav class="navbar navbar-default">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Bootstrap nav menu</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">

<li class="dropdown">
<a href="https://www.google.com" class="dropdown-toggle disabled" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Main menu 1<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">submenu1</a></li>
<li><a href="#">submenu2</a></li>
<li><a href="#">submenu3</a></li>

</ul>
</li>
<li class="active"><a href="#">Main menu 2 <span class="sr-only">(current)</span></a></li>
<li><a href="#">Main menu 3</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">

最佳答案

尝试这样的事情,你可以检查元素,当你将鼠标悬停在下拉列表上时,disable 类将被删除

$(function(){
var $windowWidth = $(window).width();
$('ul.nav').on('mouseover','.dropdown',function(){
if($windowWidth < 768){
$(this).find('a').removeClass('disabled');
}
});
});

检查演示

$(function(){
var $windowWidth = $(window).width();
$('ul.nav').on('mouseover','.dropdown',function(){
if($windowWidth < 768){
$(this).addClass('open');
$(this).find('a').removeClass('disabled');
}
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<div class="container">
<nav class="navbar navbar-default">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Bootstrap nav menu</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">

<li class="dropdown">
<a href="https://www.google.com" class="dropdown-toggle disabled" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Main menu 1<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">submenu1</a></li>
<li><a href="#">submenu2</a></li>
<li><a href="#">submenu3</a></li>

</ul>
</li>
<li class="active"><a href="#">Main menu 2 <span class="sr-only">(current)</span></a></li>
<li><a href="#">Main menu 3</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

关于javascript - 带有子菜单的 Bootstrap 导航栏 - 如何删除 768 下的类 "disabled"@media width,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41690638/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com