简体   繁体   English

检查哪个事件使用jQuery触发了该函数?

[英]Check which event fired the function with jQuery?

How can i check which event called my function on Javascript with Jquery? 如何使用Jquery检查在Javascript上调用我的函数的事件?

Like i have: 像我一样:

var mycall= function() { 
    alert('Which Witch is Which?');
}

$(window).load(mycall);
$(window).resize(mycall);

I understand that i could pass a parameter to the function, still i'm interested in a way to do this without passing any parameters. 我知道我可以将一个参数传递给函数,我仍然对这种方法感兴趣而不传递任何参数。

Use the type property in the event object: event对象中使用type属性

var mycall = function(e) { 
  alert(e.type);
};

Add an event to the function args and then event.type will give tell which event is triggered. 向函数args添加一个事件,然后event.type将告诉tell触发了哪个事件。 See below, 见下文,

var mycall= function(e) { 
    alert(e.type);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM