同时使用call(this)并将事件对象传递给stoppropagation

时间:2012-08-07 23:25:54

标签: jquery

我有一小段像这样的jQuery:

$('.remove-header').on('click',function(){
  arc.event_handler.remove_header_click.call(this);
});

.remove-header嵌套在一个类似的对象中,所以我需要调用event.stopPropogation,但通常我会传递这样的引用:

$('.remove-header').on('click',function(event){
  arc.event_handler.remove_header_click(event);
});

我如何将这两者合并到一个电话中?我试过的几件事似乎没有用。

THX

2 个答案:

答案 0 :(得分:1)

传递event对象可以通过将其作为附加参数传递给.call来完成:

$('.remove-header').on('click',function(event){
  arc.event_handler.remove_header_click.call(this, event);
});

查看the documentation for .call

但您也可以直接停止事件处理程序内的传播,如jfriend00 showed

答案 1 :(得分:1)

我不是百分百肯定我知道你在问什么,但你不能这样做:

$('.remove-header').on('click',function(event){
     event.preventDefault();
     arc.event_handler.remove_header_click.call(this, event);
});
相关问题