说我有这个
<div class="parent">
<div class="child1"></div>
<div class="child2"></div>
</div>
只要 .child2 没有被点击,当 .parent 被点击时我如何让 jQuery 做一些事情?我尝试使用 event.stopPropagation() 但它没有用。 这是我的:
$('body').on({
click: function(event)
{
event.stopPropagation();
}
},'.child2');
$('body').on({
click: function()
{
//blah blah
}
},'.parent');
最佳答案
您可以使用事件对象的stopPropagation
方法:
$('.parent').on('click', function(){
// ...
}).find('.child2').on('click', function(event){
event.stopPropagation();
});
关于javascript - 父 div 上的 jQuery 但不是 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17542143/