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

后端 未结 2 1214
深忆病人
深忆病人 2020-12-06 08:59

If you attach two or more event handlers to an HTML element, they would be executed one after the other. However, if you want to stop the subsequent event handlers, based on

2条回答
  •  被撕碎了的回忆
    2020-12-06 09:48

    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/

提交回复
热议问题