防止其他注册点击事件?

时间:2011-11-06 15:02:10

标签: jquery

页面上有p元素。

p有2次绑定点击(请保留这一点。我知道还有其他选项。)

 $('p').click (function (e) {
    e.preventDefault();  //<== not helping me as I thought it should
    alert('1');
    });

//...later on the same page...

    $('p').click (function ( ) {
    alert('2');
    });

我希望第一个代码阻止执行第二个代码( NOT VIA FLAGS)

这种做法最elegant的方式是什么?

1 个答案:

答案 0 :(得分:6)

e.stopImmediatePropagation();

在第一个函数中

编辑:显示悬停的演示不受影响:

http://jsfiddle.net/VEuRu/1/

相关问题