jQuery绑定对象上的所有事件 [英] jQuery bind all events on object

查看:77
本文介绍了jQuery绑定对象上的所有事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我有一个对象,它触发针对它的事件.

I have an object that gets events triggered against it.

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

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

推荐答案

您可以通过将所有标准javascript事件包含在以空格分隔的绑定调用中来绑定所有标准javascript事件. jQuery文档提供以下列表:

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

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);
    });

如果要查找自定义事件,则必须查看API并将其绑定.没有出现可以绑定任何任何事件.

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.

这篇关于jQuery绑定对象上的所有事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆