单击链接时忽略表单击function

当用户在我的表中点击一行时,我有一个单击方法。

$('.table > tbody > tr').click(function () { if ($(this).hasClass("info")) { $(this).removeClass("info"); } else { $(this).addClass("info"); } }); 

但是,某些单元格中存在链接,如果单击链接,我想忽略上述方法。 我怎样才能做到这一点?

只需检查是否使用event.target.closest()单击了一个链接:

 $('.table > tbody > tr').click(function (e) { //Catch event here if($(e.target).closest('a').length) return; // Add this if ($(this).hasClass("info")) { $(this).removeClass("info"); } else { $(this).addClass("info"); } }); 

您可以单击从锚点传播的事件

 $('.table > tbody > tr a').click(function (e) { e.stopPropagation() }); 

http://jsfiddle.net/JkebH/