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()
回调中的函数?