为什么event.stopImmediatePropagation()在IE以外的所有浏览器中都有效? [英] Why is event.stopImmediatePropagation() working in all browsers except IE?

查看:191
本文介绍了为什么event.stopImmediatePropagation()在IE以外的所有浏览器中都有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过一些测试后,我注意到event.stopImmediatePropagation()在IE中不起作用(以下用法)。但是,它适用于Chrome,FF,Safari和Opera。给出了什么?

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?

参见 这个小提琴 在IE中重复(在其他浏览器中测试小提琴,看它是否有效)。

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

小提琴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;' />


推荐答案

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

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.

用于的jquery版本你的代码不起作用。这个 jsfiddle 在IE中完美运行,代码完全相同。唯一的区别是它使用jQuery 1.9.1而不是jQuery 1.8.3

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

这篇关于为什么event.stopImmediatePropagation()在IE以外的所有浏览器中都有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆