简体   繁体   English

如何确定javascript或jquery中事件处理程序被触发的顺序?

[英]how to determine the order of being triggered of a event handler in javascript or jquery?

如果多个事件处理程序将响应一个事件,事件处理的回调函数在不同的地方被定义,我怎么能知道哪些处理程序将首先触发,egwhen检查on/off一个radioradio结合多个处理程序,所以如何判断哪一个先被执行?

Javascript event handler order Javascript事件处理程序命令

If you use JQuery to bind your events, it guarantees that handlers are fired in the same order that they were bound. 如果使用JQuery来绑定事件,则可以保证处理程序的触发顺序与它们绑定的顺序相同。 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. 如果你不能使用JQuery或类似的框架,你可以通过使用自己的自定义偶数绑定轻松地模拟它,其中你的泛型处理程序是一个函数,它保存一系列函数并按顺序调用它们。

Documentation - 文件 -
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. 在执行所有处理程序之后,事件沿着正常事件传播路径继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM