jQuery,单击可点击元素内的元素

问题描述 投票:9回答:1

我有以下HTML语法:

<table><tr><td id="click1"><a href="somelink.html" id="click2">here's the link</a></td></tr></table>

我有像这样的jquery语法

$('td#click1').ajaxify();
$('a#click2').fancybox();

我的问题是,如果我点击#click2然后选择#click1

如何才能在不调用#click2的情况下选择#click1

jquery click
1个回答
26
投票
$('a#click2').click(function(event){

    event.stopPropagation();

})

你可以调用stopPropagation,以防止事件冒泡DOM树。

© www.soinside.com 2019 - 2024. All rights reserved.