防止点击触发()
问题描述:
我有一个较小的div嵌套在一个更大的div内。 1个特定的小格子#small
和大格子#large
已将jQuery click()
事件处理程序附加到它们。防止点击触发()
问题:我如何使它这样,当点击发生的是一个更小的嵌套DIV中,大格的click()
处理程序不开火,只有一个小格是什么?如果点击发生在其他较小的div上,则较大的div的click()
仍然必须触发。
HTML
<div id="large">
<div id="small"></div>
<div id="small_2"></div>
<div id="small_3"></div>
</div>
jQuery的
$("#large").click(function() {
console.log('large');
}
$("#small").click(function() {
console.log('small');
}
答
$("#small").click(function(e) {
e.stopPropagation();
console.log('small');
}
就存在
大,不知道。谢谢! :) – Nyxynyx 2011-12-28 05:23:10