[英]JavaScript setTimeOut function not working
I have the following JS code 我有以下JS代码
$(document).ready(function(){
update_items();
adjust_size_of_menu();
});
var adjust_size_of_menu = function() {
// global boolean set in update_items_count();
if ( !items_updated )
{
alert("Treatment of update_items() not done yet");
setTimeOut( function(){ adjust_size_of_menu(); }, 1000);
}
// More treatment goes here
}
As you can see, I am setting a variable in the first function. 如您所见,我正在第一个函数中设置一个变量。 This variable must be
true
before I proceed with the execution of the rest of the instructions in the second function. 在继续执行第二个功能中的其余指令之前,此变量必须为
true
。
The problem here is that the first time I go into adjust_size_of_menu()
, it shows me the alert, which is fine. 这里的问题是,当我第一次进入
adjust_size_of_menu()
,它会向我显示警报,这很好。 After that, it should wait 1 second then re-execute the adjust_size_of_menu()
from the beginning until the item_updated boolean is true
, then we continue with the rest of the code. 之后,它应该等待1秒钟,然后
adjust_size_of_menu()
开始重新执行adjust_size_of_menu()
,直到item_updated布尔值为true
为止,然后我们继续其余的代码。
What is the problem with this code? 此代码有什么问题? I've already used the same approach elsewhere and worked just fine.
我已经在其他地方使用了相同的方法,并且效果很好。
setTimeOut
is not a built-in function in javascript. setTimeOut
不是javascript中的内置函数。 If you've used it elsewhere, it's because you or someone else declared it. 如果您在其他地方使用过它,那是因为您或其他人声明了它。 The correct spelling is
setTimeout
. 正确的拼写是
setTimeout
。 Note the lowercase "o". 注意小写字母“ o”。
https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout https://developer.mozilla.org/zh-CN/docs/Web/API/WindowTimers/setTimeout
javascript是区分大小写的语言,应设置为setTimeout()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.