Javascript event handler order

后端 未结 4 1423
我在风中等你
我在风中等你 2020-12-03 14:37

I have an input field, which has two event handlers bound to it.

Validate & AutoSave

Obviously I want to validate before I save. If validation fails, the

4条回答
  •  爱一瞬间的悲伤
    2020-12-03 15:11

    If you use JQuery to bind your events, it guarantees that handlers are fired in the same order that they were bound. Otherwise the order is officially undefined.

    If you cannot use JQuery or a similar framework you can easily simulate this by using your own custom even binding, where your generic handler is a function which keeps an array of functions and calls them in order.

提交回复
热议问题