Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery检查或等待变量具有值,然后继续_Jquery_Promise_Wait - Fatal编程技术网

jquery检查或等待变量具有值,然后继续

jquery检查或等待变量具有值,然后继续,jquery,promise,wait,Jquery,Promise,Wait,在继续函数之前,是否可以等待或检查具有值的变量 var someVar = false; $('.someEl').animate({'marginLeft': 100}, 500, function () { // animating complete someVar = true; }); function someFunction () { // watch someVar to be true and then run the code in this fun

在继续函数之前,是否可以等待或检查具有值的变量

var someVar = false;

$('.someEl').animate({'marginLeft': 100}, 500, function () {
    // animating complete
    someVar = true;
});

function someFunction () {
    // watch someVar to be true and then run the code in this function
}

someFunction();
直截了当地说:

var someVar = false;

$('.someEl').animate({'marginLeft': 100}, 500, function () {
    // animating complete
    someVar = true;
    someFunction();
});

function someFunction () {
    // watch someVar to be true and then run the code in this function
}
用一种手表:

var someVar = false;

$('.someEl').animate({'marginLeft': 100}, 500, function () {
    // animating complete
    someVar = true;
});

function someFunction () {
    if (someVar) { do.. }
    else setTimeout(function() { someFunction(); }, 1);
}

这很可能是解决实际问题的错误途径。为什么不能调用
.animate()
回调中的函数?