导航栏折叠后的Bootstrap 3,切换不会重新打开导航 [英] Bootstrap 3 after navbar collapse, toggle wont reopen nav

查看:90
本文介绍了导航栏折叠后的Bootstrap 3,切换不会重新打开导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解决一个问题,当我单击移动视图中的导航栏菜单项时,导航栏仍保持展开状态.这对我来说不起作用,因为我的菜单项指向div ID.我在这里阅读了将以下内容添加到href标签中的解决方案.

I was trying to solve an issue where when I clicked on a navbar menu item in mobile view the navbar remained expanded. this didn't work for me as my menu item was pointing to a div ID. I read here of a solution to add the below to my a href tag.

data-toggle="collapse" data-target=".navbar-collapse" 

这对我不起作用,但是我可以使用我在github https://github.com/twbs/bootstrap/issues/12852

this did not work for me but I could get it to work using a javascript fix I found on github https://github.com/twbs/bootstrap/issues/12852

$(document).on('click','.navbar-collapse.in',function(e) {
if( $(e.target).is('a') ) {
    $(this).collapse('hide');
}
});

现在的问题是,导航栏被隐藏后,我无法第二次打开它.

Now the problem is that after the navbar was hidden I could not open it a second time.

还有其他人有这个问题或解决方案吗?

Anyone else have this problem or a solution?

推荐答案

将折叠参数从hide更改为toggle.

$(this).collapse('toggle');

有关更多信息,请参见引导文档.

See more at bootstrap docs.

这篇关于导航栏折叠后的Bootstrap 3,切换不会重新打开导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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