2

有两个事件:

 $('body').mouseup(function(e){}

$('.toggle').click(function(e){}

我只希望其中一个触发。我试过

 e.stopPropagation(); e.preventDefault(); return false; 

但这似乎并不能阻止它。有任何想法吗?首先触发 mouseup。

谢谢。

4

1 回答 1

4

问题是它们是两个不同的事件。如果你想阻止 body.onmouseup,你需要在 .toggle 上添加一些东西来捕捉/停止 mouseup 事件;像

$('.toggle').mouseup(function(e){
    e.stopPropagation();
    e.preventDefault();
    // these two are older ways I like to add to maximize browser compat
    e.returnValue = false;
    e.cancelBubble = true;
    return false; 
}
于 2012-02-18T00:38:57.880 回答