自动关闭响应式导航栏 [英] Close responsive navbar automatically

查看:27
本文介绍了自动关闭响应式导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Bootstrap 响应式导航栏.当导航栏折叠并打开菜单并单击菜单项时,菜单不会自动关闭,我必须自己手动完成.

I'm using a Bootstrap responsive navbar. When the navbar is collapsed and I open the menu and click on a menu item, the menu doesn't close automatically, and I have to do it myself manually.

是否可以在单击其中一个按钮后自动关闭菜单?

Is it possible to make the menu close automatically after clicking on one of the buttons?

推荐答案

正如 Maximus 在下面指出的那样,3.x bootstrap 解决方案是:

As Maximus points out below, the 3.x bootstrap solution is:

$('.navbar-collapse a').click(function(){
    $(".navbar-collapse").collapse('hide');
});

https://jsfiddle.net/yohuLuj2/

2.x bootstrap 的旧答案:

您应该能够通过向列表项添加点击处理程序然后以这种方式关闭导航来实现这一点.

You should be able to do that by adding a click handler to the list items and then closing the nav that way.

$('.nav-collapse').click('li', function() {
    $('.nav-collapse').collapse('hide');
});

这是一个jsfiddle:http://jsfiddle.net/hajpoj/By6ym/4/

Heres a jsfiddle: http://jsfiddle.net/hajpoj/By6ym/4/

这篇关于自动关闭响应式导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆