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;' />