2016-12-14 56 views
-2

我正在使用這些來創建可點擊的鏈接行,但我不想包含複選框,因爲我正在使用複選框來過濾另一個操作。如何防止特定目標的點擊處理程序

是否有可能除了行上的複選框?

如何防止點擊處理特定目標

jQuery(document).ready(function($) { 
 
    $(".clickable-row").click(function() { 
 
    window.document.location = $(this).data("href"); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table class="table table-striped table-bordered table-hover table_adj table-checkable txt-col mar_bot_10"> 
 
    <thead> 
 
    <tr> 
 
     <th> 
 
     <label class="mt-checkbox mt-checkbox-single mt-checkbox-outline"> 
 
      <input class="mail-group-checkbox" type="checkbox" value="movetofilter"> <span></span> 
 
     </label> 
 
     </th> 
 
     <th>a</th> 
 
     <th><span data-placement="bottom" data-toggle="tooltip" title="Added Reference">b</span> 
 
     </th> 
 
     <th>c</th> 
 
     <th>d</th> 
 
     <th><span data-placement="bottom" data-toggle="tooltip" title="Received Message">e</span> 
 
     </th> 
 
     <th><span data-placement="bottom" data-toggle="tooltip" title="Received Date">f</span> 
 
     </th> 
 
     <th>g</th> 
 
     <th>h</th> 
 
     <th class="text-right">i</th> 
 
    </tr> 
 
    </thead> 
 
    <tbody> 
 
    <tr class='clickable-row' data-href='http://stackoverflow.com'> 
 
     <td> 
 
     <label class="mt-checkbox mt-checkbox-single mt-checkbox-outline"> 
 
      <input class="mail-group-checkbox" type="checkbox" value="movetofilter"> <span></span> 
 
     </label> 
 
     </td> 
 
     <td>1 
 
     </td> 
 
     <td class="text70px">1</td> 
 
     <td class="text170px">1</td> 
 
     <td>212</td> 
 
     <td class="text40px">23</td> 
 
     <td class="text70px">2</td> 
 
     <td class="text40px">4</td> 
 
     <td class="text70px">5</td> 
 
     <td class="text70px text-right">6</td> 
 
    </tr>

+0

請爲您添加html代碼。 –

+0

請澄清您的具體問題或添加其他詳細信息,以突出顯示您的需要。正如目前所寫,很難說清楚你在問什麼 –

+0

向我們展示一行的html –

回答

0

可以驗證使用event.target被點擊了什麼元素。

$(".clickable-row").click(function(event) { 
    // Check if target is NOT inside '.mt-checkbox' 
    if(!$(event.target).closest('.mt-checkbox').length){ 
     window.document.location = $(this).data("href"); 
    } 
}); 
+0

非常感謝你這麼多Alexandru Severin – kris

+0

@kris,你應該已經離開了html在未來的讀者對我的答案有意義的問題。另外,如果他們通過點擊除了他們之外的複選標記來解決您的問題,請考慮接受答案。 –

+0

對不起Alexandru Serverin - 我會嘗試再次添加 – kris

相關問題