How to prevent other event handlers, from first handler, in jQuery

喜欢而已 提交于 2019-11-27 23:26:28

See event.stopImmediatePropagation() - http://api.jquery.com/event.stopImmediatePropagation/

According to the jQuery API docs, this method:

Keeps the rest of the handlers from being executed and prevents the event from bubbling up the DOM tree.

The solution is browser specific. See dojo.stopEvent:

dojo.stopEvent = function(/*Event*/ evt){
    // summary:
    //        prevents propagation and clobbers the default action of the
    //        passed event
    // evt: Event
    //        The event object. If omitted, window.event is used on IE.
    if(has("dom-addeventlistener") || (evt && evt.preventDefault)){
        evt.preventDefault();
        evt.stopPropagation();
    }else{
        evt = evt || window.event;
        evt.cancelBubble = true;
        on._preventDefault.call(evt);
    }
};

Updated fiddle: http://jsfiddle.net/pFp7P/1/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!