2016-12-14 33 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

相关问题