本文介绍了jQuery:等待/延迟1秒而不执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法在jQuery中使用 .delay
方法:
I can't get the .delay
method working in jQuery:
$.delay(3000); // not working
$(queue).delay(3000); // not working
我正在使用while循环等待一个不受控制的变化值大于或等于另一个,我找不到任何方法来执行X秒的执行。
I'm using a while loop to wait until an uncontrolled changing value is greater than or equal to another and I can't find any way to hault execution for X seconds.
推荐答案
$ .delay用于延迟队列中的动画,而不是暂停执行。
$.delay is used to delay animations in a queue, not halt execution.
您需要递归调用一个方法,该方法每秒使用<$ c $执行一次检查c> setTimeout :
Instead of using a while loop, you need to recursively call a method that performs the check every second using setTimeout
:
var check = function(){
if(condition){
// run when condition is met
}
else {
setTimeout(check, 1000); // check again in a second
}
}
check();
这篇关于jQuery:等待/延迟1秒而不执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!