问题描述:

Is there a way to say on any event fire

 $('#foo').bind('click', function() {

alert($(this).text());

});

I am trying to test a piece of code for a certain event and not going in there. Just want it to fire fore ANY event.

 $('#foo').bind('ANY', function() {

alert($(this).text());

});

网友答案:

There's no shorthand for listening to all events.

The closest thing you can get out of the box would be specifying them manually:

$('#foo').bind('blur change click dblclick focus focusin focusout hover keydown ...', function() {
    alert($(this).text());
});

Note that plugins may fire their own events, perhaps namespaced. You can't listen to these events without knowing them and manually specifying them.

网友答案:

You can specify every event separated by spaces in the first argument of the bind function. This will bind to all events. To view all events covered by jquery visit the documentation.

网友答案:

I don't think that is possible, but you can use Firebug to view all events that are bound to a page element.

Open up Firebug and then in the console write the following:

$("#foo").data("events"); 

That should display any event that is bound to the #foo element.

相关阅读:
Top