jQuery:同一个事件的多个处理程序

问题描述:

如果我将两个事件处理程序绑定到相同元素的同一个事件中,会发生什么?

What happens if I bind two event handlers to the same event for the same element?

例如:

var elem = $("...")
elem.click(...);
elem.click(...);

最后一个处理程序win还是将会运行两个处理程序?

Does the last handler "win", or will both handlers be run?

两个处理程序都将运行,jQuery事件模型允许一个元素上的多个处理程序,因此后来的处理程序不会覆盖较旧的处理程序。

Both handlers will run, the jQuery event model allows multiple handlers on one element, therefore a later handler does not override an older handler.

处理程序将按照他们的顺序执行绑定