如果你有几个事件处理程序,那么你怎么能离开/停止链?
$('input').keydown(function(e){
console.log('first keydown');
});
$('input').keydown(function(e){
console.log('second keydown');
// leave/escape the event chain and skip the third keydown
});
$('input').keydown(function(e){
console.log('third keydown');
});
答案 0 :(得分:1)
stopImmediatePropagation应该可以解决问题:http://api.jquery.com/event.stopimmediatepropagation/
$('input').keydown(function(e){
console.log('first keydown');
});
$('input').keydown(function(e){
console.log('second keydown');
// leave/escape the event chain and skip the third keydown
e.stopImmediatePropagation();
});
$('input').keydown(function(e){
//will not be logged
console.log('third keydown');
});
jsfiddle:http://jsfiddle.net/8a5zt6qu/1/