2016-01-13 15 views
0
<tr> 
    <td>1</td> 
    <td>2</td> 
    <td>3</td> 
    <td>4</td> 
    <td> 
    <a href="/go_to_somewhere"> 
     x 
    </a> 
    </td> 
</tr> 

想象一下上面的元素我有一个tr事件,当我点击x链接时该如何委派点击?内联代表事件处理程序Javascript

我知道可以做象下面

$('a').click(function(e){ 
e.delegate(); 
console.log(stop tr click, fire this) 
} 
+0

的可能的复制[jQuery选择:委托点击事件只与特定的数据TR元件](http://stackoverflow.com/questions/3187839/jquery-selector-delegate-click-event-to-only -tr-elements-with-specific-data) –

+0

@YoYo已经告诉你,我没有在js中为'a'标签添加任何事件。 – Jennifer

+0

你想在'a'标签上点击时停止执行'tr'事件处理程序。是对的吗? – Venugopal

回答

0

event.stopPropagation()防止电流事件的进一步传播。

$('a').click(function (event) { 
    event.stopPropagation(); 
    console.log("stop tr click, fire this"); 
};