【发布时间】:2013-03-12 08:37:33
【问题描述】:
我使用了这段代码(后面是填充“tcap”文本区域的 xmlhttprequest):
st=setTimeout(checkme(),4000)
checkme() 在哪里:
function checkme() {
if (typeof (st) != 'undefined') clearTimeout(st)
if (document.getElementById("tcap").innerHTML.length > 0) {
document.getElementById('waitmsg').style.display = 'none'
} else {
st = setTimeout(checkme(), 1000)
}
}
如果我运行它,它会冻结 Firefox 19,并且没有错误消息。 但是,如果我将第一个参数(在代码和 checkme() 函数中)替换为:
st=setTimeout(function(){checkme()},4000)
它工作正常。
所以我的问题是:调用checkme() 函数时有没有anon 函数有什么区别?为什么在第一种情况下它会冻结 Firefox?
谢谢
【问题讨论】:
标签: javascript settimeout