如何检测jquery触发器事件完成? [英] How do I detect a jquery trigger events completion?

查看:65
本文介绍了如何检测jquery触发器事件完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试触发第二个依赖于第一个事件的事件,如下所示:

I'm trying to trigger a second event dependent on the first like so:

...
$('#productFamilyId').val(data.contents.productfamily);
$('#productFamilyId').trigger('change', function() {
    $('#productId').val(data.contents.product);
    $('#productId').trigger('change');
});

在尝试触发第二个事件之前,它不会等待第一个触发器完成。是否可以等待第一个触发器完成?

It's not waiting for the first trigger to complete before attempting to trigger the second event. Is it possible to wait for the first trigger to complete?

推荐答案

触发方法没有回调。额外的参数就是 - 参数。

There is no callback for the trigger method. The extra parameters are just that - parameters.

http: //api.jquery.com/trigger/

您实际在做的是在第二个函数中运行代码,然后将结果作为参数进入由trigger调用的事件处理程序。如果希望它们按顺序运行,则需要在第一个事件的事件处理程序中触发第二个事件。

What you're actually doing is running the code in the second function and then passing the result as a parameter into the event handler called by trigger. You need to trigger the 2nd event within the event handler for the first event if you want them to run in sequence.

这篇关于如何检测jquery触发器事件完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆