2017-04-10 11 views
0

ご協力いただきありがとうございます。サイドバーメニューリストを含む本文の任意の場所をクリックすると、サイドバーを閉じるためにボディのクリックを使用しています。私は、リストメニューのドロップダウンメニューをクリックするだけで体のクリックを無効にしたい。ドロップダウンボタン以外のサイドバーのリストメニューでevent.stopPropagationを使用してください

の1-私は「私はthebelowコードを使用しようとしましたが、私はそれはdoesnのことを知っている番目のドロップダウンメニューを開き、李に身体のクリックイベントを無効にするには、本体のクリックイベントのために

$(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-このコードを使用t。私は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(); 
    }); 

答えて

0

あなたはクラスと変更されたクラスを使用すると、このクラスのクラス= "変更項目"「ONMイベントを追加することができます。class = "変更項目" セレクタによって

  <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> 

オープンダイアル:

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

and not active you can toggle this class: 

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

event.stopPropagation()は使用しません。

+0

あなたの返信では#Enlightener thansですが、すでに問題の解決策が見つかりました。私はbody上ではなく、speceficクラスのclickイベントを適用しました。 –

関連する問題