setTimeout()递归调用不加引号出错的解决方法


用了setTimeout()想实现递归调用,如果第一个参数不加引号的话,火狐提示setTimeout():uselesssetTimeout call (missing quotes around argument?)如果加引号的话 ,火狐会提示那个函数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();

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3