jQuery: more than one handler for same event

后端 未结 8 1472
终归单人心
终归单人心 2020-11-27 03:14

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

For example:

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


        
8条回答
  •  面向向阳花
    2020-11-27 03:35

    jQuery's .bind() fires in the order it was bound:

    When an event reaches an element, all handlers bound to that event type for the element are fired. If there are multiple handlers registered, they will always execute in the order in which they were bound. After all handlers have executed, the event continues along the normal event propagation path.

    Source: http://api.jquery.com/bind/

    Because jQuery's other functions (ex. .click()) are shortcuts for .bind('click', handler), I would guess that they are also triggered in the order they are bound.

提交回复
热议问题