Bootstrap 3 Hide Dropdown Menu on Menu Item Click

后端 未结 6 1133
眼角桃花
眼角桃花 2021-02-04 07:05

Check out the fiddle. I have a basic Bootstrap 3 responsive nav like so:

    
&
6条回答
  •  無奈伤痛
    2021-02-04 07:48

    If need to fix this on bootstrap 4, try this jquery snippet. It works in this way: If navbar is expanded, nothing happens, (normal bootstrap behavior). If navbar is collapsed, after a click event, closes the navbar. Works on bootstrap 4

      $(".navbar a").click(function(event) {
          // check if window is small enough so dropdown is created
          var toggle = $(".navbar-toggler").is(":visible");
          if (toggle) {
              $(".navbar-collapse").collapse('hide');
          }
      });
    

提交回复
热议问题