2

经过一些测试后,我注意到这event.stopImmediatePropagation()在 IE 中不起作用(按照下面的用法)。但是,它适用于 Chrome、Firefox、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;' />
4

1 回答 1

3

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

您的代码中使用的 jquery 版本不起作用。这个jsfiddle在IE下完美运行,代码一模一样。唯一的区别是它使用 jQuery 1.9.1 而不是 jQuery 1.8.3

于 2013-03-12T01:50:35.920 回答