jquery多事件处理程序 [英] jquery multiple event handlers
问题描述
我已经根据我在最近的项目中的类名定义了事件处理程序。
I have defined event handlers according to their classnames in the latest project that I'm working on.
具有类名foo的所有元素应以特定方式对更改事件进行响应。所有类名为bar的元素都应以其他方式进行响应。
for ex. all element with the class name "foo" should respond in a particular way on change event. and all elements with the class name "bar" should respond in some other way.
现在我的一些元素属于这两个类,即class =foo bar应该以两种方式做出回应。现在只有一个事件处理程序函数被调用。
Now some of my elements fall under both classes i.e. class="foo bar" and they should respond in both ways. Right now, only one of the event handler function is being called.
如何使两个响应同时执行。
How can I make both the responses execute simultaneously.
推荐答案
这取决于你如何绑定事件。如果您通过jQuery绑定它们,而不是通过覆盖处理程序x.onchange = function(){...}
- 所有绑定的事件处理程序将被执行。这是因为jQuery 队列事件处理程序而不是覆盖以前的绑定。
It depends on how you are binding the events. If you are binding them via jQuery and not overwriting the handlers via x.onchange = function() { ... }
- all the bound event handlers will get executed. This is because jQuery queues the event handlers instead of overwriting the previous binding(s).
一个href =http://jsfiddle.net/maEjL/ =noreferrer> fiddle
来查看多个事件被触发:
和
Check this fiddle
to see multiple events getting fired:
and
检查这个 fiddle
,以了解事件处理程序如何被覆盖,只会导致最后绑定的处理程序触发
这篇关于jquery多事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!