[英]javascript variable setting
I have a small if statement that runs when a function is run. 我有一个小的if语句,在运行函数时运行。 The issue is that the variable timeout_value is always defined as 0 even after the if statement executes successfully.
问题是即使在if语句成功执行后,变量timeout_value也始终定义为0。 What am I doing wrong?
我究竟做错了什么?
//update on interval
var timeout_value=0;
//set interval based on number of users
if (json.countusers==2 && timeout_value!=3){
alert(timeout_value);
timeoutID2 = setInterval(refresh, 3000);
timeout_value=3;
}
Are you defining var timeout_value=0;
你定义
var timeout_value=0;
in the right scope? 在合适的范围内? Move it out of your method.
将其移出您的方法。
Do you call this from inside a function? 你是从一个函数里面调用它吗?
var
makes the variable local, so it is not available in the global scope. var
使变量成为局部变量,因此在全局范围内不可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.