javascript setInterval()变量作用域问题

发布网友

我来回答

3个回答

热心网友

你最好把全文贴出来 这样看不出来 你2个函数引用时是怎么个情形

按道理来说 clearInterval(updateheight)是无效的 如果updateheight真的是局部的话,不过不是没特殊情况 要看代码才知道

热心网友

updateheigth 只能在updateHeight() 这个Function里有用。
只能定义全局
var updateheight;
function updateHeight(){
updateheight = setInterval(function(){
if (objload) {
obj.adjustHeight();
clearInterval(updateheight);
}
}
, 1000);
}

回答完了才看到问题的最后一句话。=。=。
还是提交了。

热心网友

对了, updateheight 的作用域只限于函数内.

var updateheight ;
function updateHeight(){
updateheight = setInterval('adjustHeight()', 1000);
}
这样就可以了

提醒一下: 变量名和函数名太相似了, 千万别看错了

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com