如标题所述,我想在子元素的mousedown事件触发时停止父元素的click事件。
我的HTML代码如下:
<div class='parent'>
<div class='child'></div>
</div>
我的jQuery代码如下:
$('.child').mousedown(function(){
//what can I write here to prevent parent's click event from fireing?
//I've tried event.stopPropagation() as well as
//event.stopImmediatePropagation() already
});
$('.parent').on('click',function(){...})
event.stopPropagation()
吗? - nnnnnn$('.child'').on('click',function(event){ event.stopPropagation()console.log('child click');});
。有趣的是:.child
的点击事件并不总是触发,而.child
的 mousedown 事件和.parent
的点击事件则像往常一样工作。 - Lin Shen