jQuery绑定对象上的所有事件[重复]

时间:2022-06-16 02:21:56

Possible Duplicate:
How all events of dom element can be bind?

可能重复:如何绑定dom元素的所有事件?

I have an object that gets events triggered against it.

我有一个对象触发事件触发它。

How do I bind all the events and console.log the event name?

如何绑定所有事件和console.log事件名称?

1 个解决方案

#1


8  

You can bind all the standard javascript events by including them in the bind call separated by spaces. The jQuery docs provide this list:

您可以通过将它们包含在由空格分隔的绑定调用中来绑定所有标准javascript事件。 jQuery文档提供了这个列表:

blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup  mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error

So, to bind the event for click, blur and focus:

因此,要绑定事件以进行单击,模糊和聚焦:

   $('#foo').bind('click blur focus', function(event) {
      console.log(event.type);
    });

If you're looking for custom events, you'll have to look at the API and bind those as well. There doesn't appear to be any way to bind on any event.

如果您正在寻找自定义事件,则必须查看API并将其绑定。似乎没有任何方法可以绑定任何事件。

#1


8  

You can bind all the standard javascript events by including them in the bind call separated by spaces. The jQuery docs provide this list:

您可以通过将它们包含在由空格分隔的绑定调用中来绑定所有标准javascript事件。 jQuery文档提供了这个列表:

blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup  mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error

So, to bind the event for click, blur and focus:

因此,要绑定事件以进行单击,模糊和聚焦:

   $('#foo').bind('click blur focus', function(event) {
      console.log(event.type);
    });

If you're looking for custom events, you'll have to look at the API and bind those as well. There doesn't appear to be any way to bind on any event.

如果您正在寻找自定义事件,则必须查看API并将其绑定。似乎没有任何方法可以绑定任何事件。