Close responsive navbar automatically

前端 未结 12 1670
天命终不由人
天命终不由人 2020-12-05 02:04

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

12条回答
  •  爱一瞬间的悲伤
    2020-12-05 02:42

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

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

    https://jsfiddle.net/yohuLuj2/


    Old Answer for 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');
    });
    

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

提交回复
热议问题