我不敢相信我对此有疑问。我的 setTimeout 是:
setTimeout(function(){showContent(entries, 0);}, 500);
我也试过:
(function(entries, index){
clear_show_content = setTimeout(function(){
showContent(entries, index);
}, 500);
})(entries, 0);
并且在 showContent(entries, index)
中索引未定义。请告诉我,我只是遗漏了一些明显的东西。
编辑:这段代码今晚造成了很多问题:)
var clear_show_content;
function showContent(json){
var entries = json;
$('#content').html('');
if(checkIfNoneEntered(entries))
$('#content').append('<div class="entry">No Alumni Entered Yet!</div>');
else if(checkIfNoMatches(entries))
$('#content').append('<div class="entry">No Matches Found!</div>');
else if(checkIfError(entries))
$('#content').append('<div class="entry">There was an error!</div>');
else {
clearTimeout(clear_show_content);
$('#content').append('<table border="2" id="content_table" width="50%">');
var filler = '<img width="1" height="1" />';
clear_show_content = setTimeout((function(){showContent(entries, 0);}),
500);
}
}
function showContent(entries, index){
if(index < 0)
return;
stop = index + 10 > entries.alumnus.length ? entries.alumnus.length : 10;
start = new Date();
for(allIndex = index; allIndex < stop; allIndex++){
}//This is where it becomes proprietary, but I highly doubt the issue is after here
编辑 2: 这是问题的 jsFiddle。它在我的浏览器 (Chrome 16) 上不起作用,我目前无法访问任何其他浏览器。不过我不认为这是问题所在,因为我已经编写过数百次这样的代码。 http://jsfiddle.net/eygraber/NduqY/1/
最佳答案
您正在两次定义 showContent
函数...
关于Javascript setTimeout 参数问题(我使用的是匿名函数版本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8739569/