简体   繁体   English

防止表在单击按钮时出现可点击行

[英]Prevent table tr clickable-row when click in button

I would like some help in my code: 我想在我的代码中提供一些帮助:

I need the click in tr, but when click in the button i need open a modal... I don't need the modal code, my only question is how I can prevent the function when click the button? 我需要单击tr,但是当单击按钮时,我需要打开一个模态...我不需要模态代码,我唯一的问题是单击按钮时如何防止该功能?

Bellow my code work fine... 波纹管我的代码工作正常...

  $(".datagrid").delegate('tbody tr', 'click', function(e) { e.preventDefault(); console.log('OK.. I need this click in TR'); console.log('But, how to prevent if click comes the button???'); }); 
 .table-hover tbody tr:hover td, .table-hover tbody tr:hover th { background-color: #c5dffa; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="table" class="table table-hover dataTable datagrid" cellspacing="0"> <thead > <tr> <th></th> <th>BLABLA</th> <th>BLEBLE</th> <th>BLIBLI</th> </tr> </thead> <tbody> <tr class="clickable-row"> <td> <div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" > button </button> </div> </td> <td>blablablablabla</td> <td>blebleblebleble</td> <td>bliblibliblibli</td> </tr> </tbody> </table> 

Check e.target.tagName : 检查e.target.tagName

 $(".datagrid").delegate('tbody tr', 'click', function(e) { e.preventDefault(); if (e.target.tagName == 'BUTTON') { console.log('The button was clicked'); } else { console.log('The TR was clicked (not the button)'); } }); 
 .table-hover tbody tr:hover td, .table-hover tbody tr:hover th { background-color: #c5dffa; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="table" class="table table-hover dataTable datagrid" cellspacing="0"> <thead> <tr> <th></th> <th>BLABLA</th> <th>BLEBLE</th> <th>BLIBLI</th> </tr> </thead> <tbody> <tr class="clickable-row"> <td> <div class="dropdown"> <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true"> button </button> </div> </td> <td>blablablablabla</td> <td>blebleblebleble</td> <td>bliblibliblibli</td> </tr> </tbody> </table> 

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

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