Home >Web Front-end >JS Tutorial >Solution to the error when calling setTimeout() recursively without quotation marks_javascript skills

Solution to the error when calling setTimeout() recursively without quotation marks_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:37:061442browse

I used setTimeout() to implement a recursive call. If the first parameter is not quoted, Firefox will prompt setTimeout():uselesssetTimeout call (missing quotes around argument?). If it is quoted, Firefox will prompt that the function is undefined

function refreshNum() { 
$.ajax({ 
type: "POST", 
url: "ajax/RefreshNum.ashx", 
async: false, 
data: {}, 
success: function (data) { 
varnumArry = data.split(','); 
$.each($(".rush_left"), function (n) { 
$(this).children().eq(0).html(numArry[n]); 
}); 
setTimeout(function () { refreshNum(); }, 3000); 
//setTimeout("refreshNum",3000); //这样写就会出错,setTimeout()函数的参数,第一个一定不要用简单的函数调用,而是使用匿名函数!至于为什么就不知道了 
} 
}); 

} 
refreshNum();
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn