未定义变量时-等待 [英] While variable is not defined - wait

查看:116
本文介绍了未定义变量时-等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个click事件,它是第一次自动从其他地方触发.我的问题是它运行得太早了,因为所需的变量仍由Flash和Web服务定义.所以现在我有:

I have a click event that is triggered from another place automatically for the first time. My problem is that it runs too soon, since the required variables are still being defined by Flash and web services. So right now I have:

(function ($) {
    $(window).load(function(){
        setTimeout(function(){
            $('a.play').trigger("click");
        }, 5000);
    });
})(jQuery);

问题在于,对于互联网连接速度较慢的人来说5秒钟可能太快了,反之亦然,对于互联网连接速度较快的人来说5秒太慢了.

The problem is that 5 seconds for a person with a slow internet connection could be too fast and vice versa, for a person with a fast internet connection, it's too slow.

那么在定义someVariable之前我应该​​如何做延迟或超时?

So how should I do the delay or timeout until someVariable is defined?

推荐答案

我希望使用此代码:

function checkVariable() {

   if (variableLoaded == true) {
       // Here is your next action
   }
 }

 setTimeout(checkVariable, 1000);

这篇关于未定义变量时-等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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