问题
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