简体   繁体   English

在侧边栏列表菜单上使用event.stopPropagation(下拉按钮除外)

[英]use event.stopPropagation on sidebar list menu except dropdown button

First thanks in advance for your help. 首先,首先感谢您的帮助。 I'm using body click to close sidebar when you click anywhere in body including the sidebar menu list. 当您单击正文中的任何位置(包括侧栏菜单列表)时,我正在使用正文单击来关闭侧栏。 i want to disable body click on a dropdown menu only li in list menu. 我要禁用身体,请单击下拉菜单,只有列表菜单中的li。

1- I used this code for the body click event 1-我将此代码用于主体单击事件

$(document).ready(function() {
// Click event on body hide the element
$("#col-click1").click(function() {
  if ($(window).width() < (991) && $("body").hasClass("sidebar-open")) {
    $("body").removeClass('sidebar-open');

  }
});
});

2- To disable the body click event on li that open th dropdown menu i tried to use thebelow code, but i know it's doesn't. 2-要禁用打开下拉菜单上的li身体单击事件,我尝试使用以下代码,但我知道不是这样。 I'm looking to alternative solution as i'm new using jquery. 我正在寻找替代解决方案,因为我是使用jQuery的新手。

 <li ui-sref-active="active" id="demo222" class="sidebar-only"><a data-       target="#demo2" class="list-group-item list-group-item-success sidebar-only" data-toggle="dropdon" data-parent="#MainMenu"><img src="/app/img/icons/candidate_settings.png" id="input_img0">Mon compte</a></li>
  <div class="dropdown-menu"  id="demo2">
<li ui-sref-active="active"><a style="color: #7c868d !important; font-weight: 400 !important;" href="" style="cursor: pointer;" class="list-group-item">compte</a></li>
<li ui-sref-active="active"><a style="color: #7c868d !important; font-weight: 400 !important;" href="" style="cursor: pointer;" class="list-group-item">Support</a></li>
<li ui-sref-active="active"><a style="color: #7c868d !important; font-weight: 400 !important;" href="" class="list-group-item" ng-click="logout()">Se sign out</a></li>
</div>

   $('#demo222').click(function(event){
     event.stopPropagation();
    });

you can use class and changed class, and add event onm this class 'class="changed-item"': 您可以使用类和更改后的类,并在该类'class =“ changed-item”'中添加事件onm:

         <li ui-sref-active="active" class="changed-item" id="demo222" class="sidebar-only"><a data-       target="#demo2" class="list-group-item list-group-item-success sidebar-only" data-toggle="dropdon" data-parent="#MainMenu"><img src="/app/img/icons/candidate_settings.png" id="input_img0">Mon compte</a></li>
      <div class="dropdown-menu"  id="demo2">
    <li ui-sref-active="active" class="changed-item"><a style="color: #7c868d !important; font-weight: 400 !important;" href="" style="cursor: pointer;" class="list-group-item">compte</a></li>
    <li ui-sref-active="active" class="changed-item"><a style="color: #7c868d !important; font-weight: 400 !important;" href="" style="cursor: pointer;" class="list-group-item">Support</a></li>
    <li ui-sref-active="active" class="changed-item"><a style="color: #7c868d !important; font-weight: 400 !important;" href="" class="list-group-item" ng-click="logout()">Se sign out</a></li>
    </div>

Open dial by class="changed-item" selector: 通过class =“ changed-item”选择器打开拨号:

$('.change-item').click(function () {
   //open dialog
})

and not active you can toggle this class:

$("body").removeClass('changed-item');

and you will not use event.stopPropagation(); 并且您将不会使用event.stopPropagation();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM