gpt4 book ai didi

javascript - Bootstrap Nav Bar 不会在手机上关闭

转载 作者:行者123 更新时间:2023-11-27 23:21:43 26 4
gpt4 key购买 nike

我正在使用 Bootstrap navbar-toggle 并以类 navbar-collapsed 为目标,但我的导航栏在移动设备上不会自动关闭:

<div class="navbar navbar-default navbar-fixed-top" role="navigation" id="navbar">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<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 scrollTo" href="#intro"><img id="bg-img" src="./img/hn-logo.png"></a>
</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#intro">Home</a>
</li>
<li><a href="#section1">Products</a>
</li>
<li><a href="#section2">Learn</a>
</li>
<li><a href="#section3">Lab Testing</a>
</li>
<li><a href="#section4">Partners</a>
</li>
<li><a href="#contact">Contact</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>

最佳答案

试试这个,在脚本标签中添加这个 Jquery

 <script type="text/javascript">
$('.nav a').on('click', function () {
$('.btn-navbar').click(); //bootstrap 2.x
$('.navbar-toggle').click() //bootstrap 3.x
});
</script>

关于javascript - Bootstrap Nav Bar 不会在手机上关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40755529/

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