Why is event.stopImmediatePropagation() working in all browsers except IE?

余生颓废 提交于 2019-12-20 02:54:23

问题


After some testing I'm noticing that event.stopImmediatePropagation() does not work in IE (per usage below). However, it works in Chrome, FF, Safari, and Opera. What gives?

See this fiddle to repro in IE (test fiddle in other browsers to see it work).

fiddle javascript:

$(function(){

    $('#text').focus(function(event){
        $('#text').val('Use the button to test this.');
    });

    $('#button').click(function(event){

        // remove all handlers
        $('#text').off('focus');

        // now add this other handler in first position
        $('#text').one('focus', function(event){
            $('#text').val('Yay it works! stopImmediatePropagation works in your browser!!');
            event.stopImmediatePropagation();
        });

        // now add a handler in the 2nd position that shouldn't get run
        $('#text').focus(function(event){
            $('#text').val('Oh No! stopImmediatePropagation failed to work in your browser!!');
        });

        // now set the focus to test it
        $('#text').focus();
    });
});

fiddle html:

<input id='button' type="button" value="Start Test"/>
<input id='text' style='width:400px;' />

回答1:


IE has supported stopImmediatePropgation since IE 9 (http://msdn.microsoft.com/en-us/library/ie/ff975461(v=vs.85).aspx), but jquery is the problem.

The jquery version used in your code is not working. This jsfiddle works perfectly in IE, and the code is exactly the same. The ONLY difference is that it uses jQuery 1.9.1 instead of jQuery 1.8.3



来源:https://stackoverflow.com/questions/15351772/why-is-event-stopimmediatepropagation-working-in-all-browsers-except-ie

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