admin管理员组

文章数量:1327098

How do I refresh the page when user close the drop down menu on click outside of it.

UPDATE

 <li class="dropdown" id="u_pic_link">
                        <script>
                            $('#u_pic_link').on('hidden.bs.dropdown', function () {
                                    window.location.reload();
                                  })
                        </script>

How do I refresh the page when user close the drop down menu on click outside of it.

UPDATE

 <li class="dropdown" id="u_pic_link">
                        <script>
                            $('#u_pic_link').on('hidden.bs.dropdown', function () {
                                    window.location.reload();
                                  })
                        </script>
Share Improve this question edited Jul 24, 2015 at 12:33 Sahan Perera asked Jul 24, 2015 at 12:12 Sahan PereraSahan Perera 1942 gold badges5 silver badges17 bronze badges 3
  • there is no select it has only <a> and <ul> – Sahan Perera Commented Jul 24, 2015 at 12:35
  • @SahanPerara OP is talking about a Bootstrap dropdown. Not a <select> element – Turnip Commented Jul 24, 2015 at 12:37
  • I found the mistake, script should be nested with $(document).ready(function() { – Sahan Perera Commented Jul 24, 2015 at 12:57
Add a ment  | 

2 Answers 2

Reset to default 5

You can use the hide.bs.dropdown or hidden.bs.dropdown events...

<ul class="nav navbar-nav">
   <li class="dropdown user-dropdown" id="u_pic_link">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
      <ul class="dropdown-menu">
         <li>...</li>
      </ul>
   </li>
</ul>

$('#u_pic_link').on('hidden.bs.dropdown', function () {
  window.location.reload();
})

DEMO


If for whatever reason you need to place your javascript before the element you must use jQuery's document.ready event...

$(document).ready(function() {
    $('#u_pic_link').on('hidden.bs.dropdown', function () {
        window.location.reload();
    })
})

You can listen for an event which gets fired when the dropdown is hidden.

$('#myDropdown').on('hide.bs.dropdown', function () {
 // do something…
  window.location.reload();
 });

Official bootstrap documentation http://getbootstrap./javascript/#dropdowns

Hope this helps

本文标签: javascriptBootstrap How to refresh the page when dropdown menu is closingStack Overflow