Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:37:06
Original
1439 people have browsed it

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();
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template