Home >Web Front-end >JS Tutorial >Solution to the error when calling setTimeout() recursively without quotation marks_javascript skills
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();