Bootstrap下拉隐藏在单击选择隐藏下拉列表上

时间:2015-09-12 18:54:49

标签: javascript jquery twitter-bootstrap

点击下拉菜单中的选择,当我在选择下拉列表中选择内容时,下拉列表变为隐藏引导下拉菜单我不想隐藏

<li> <a href="#"  data-toggle="dropdown" aria-haspopup="true" class="myr-text" aria-expanded="false"> <img src="images/flag-icon.jpg" alt=""> / MYR / English</a>
              <ul class="dropdown-menu select-dropdown-menu">

                <li><p>Regional settings for your next visit</p></li>
                <li role="separator" class="divider"></li>
                <li><form class="form-horizontal" role="form">
                    <select id="basic" class="selectpicker show-tick form-control" data-live-search="true">
                      <option selected> Malaysia </option>
                      <option> Malaysia 01 </option>
                      <option> Malaysia 02 </option>
                      <option> Malaysia 03 </option>
                      <option> Malaysia 04 </option>
                    </select>
                  </form></li>
                <li><form class="form-horizontal" role="form">
                    <select id="basic" class="selectpicker show-tick form-control" data-live-search="true">
                      <option selected> Malaysian Ringgit (RM) </option>
                      <option> Malaysian Ringgit (RM) 01 </option>
                      <option> Malaysian Ringgit (RM) 02 </option>
                      <option> Malaysian Ringgit (RM) 03 </option>
                      <option> Malaysian Ringgit (RM) 04 </option>
                    </select>
                  </form></li>
                <li><form class="form-horizontal" role="form">
                    <select id="basic" class="selectpicker show-tick form-control" data-live-search="true">
                      <option selected> English </option>
                      <option> Urdu </option>
                      <option> Punjabi </option>
                      <option> Pashtoo </option>
                    </select>
                  </form></li>

              </ul>
            </li>

这是我用于显示和隐藏的jquery代码

$("body .social-nav li ul.dropdown-menu").click(function(event) {
$(this).closest('.social-nav li').addClass("open-deopdown");
    });

$(body).click(function(event) {
$(this).closest('body ul.social-nav li').removeClass("open-deopdown");
    });

1 个答案:

答案 0 :(得分:1)

试试这个:

$('body').click(function(event){
     if($(event.target).closest('.open-dropdown').length==0)
     {
        $('li').removeClass("open-dropdown");

         }
    });

$('.myr-text').click(function(){
    $(this).closest('.social-nav li').toggleClass("open-dropdown");
    });