为什么event.stopImmediatePropagation()在IE之外的所有浏览器的工作?

2019-07-21 09:05发布

经过一些测试,我注意到,event.stopImmediatePropagation()在IE(低于每使用)不起作用。 然而,它的工作原理在Chrome中,FF,Safari和Opera。 是什么赋予了?

这个小提琴在IE瑞普(测试小提琴在其他浏览器,看看它的工作)。

小提琴的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();
    });
});

小提琴HTML:

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

Answer 1:

由于IE IE 9(已支持stopImmediatePropgation http://msdn.microsoft.com/en-us/library/ie/ff975461(v=vs.85).aspx ),但jQuery是问题。

在你的代码中使用jQuery的版本是行不通的。 这的jsfiddle完美的作品在IE浏览器,和代码是完全一样的。 唯一的区别是,它采用的jQuery 1.9.1,而不是jQuery的1.8.3



文章来源: Why is event.stopImmediatePropagation() working in all browsers except IE?