我不敢相信我遇到了这个问题。我的setTimeout是:Javascript 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/
代码看起来不错,你肯定_this_是什么突破? – 2012-01-05 08:32:24
我已经过了一个小时。没有别的。 – Eliezer 2012-01-05 08:32:54
如果'showContent'的声明是'showContent(entries,index)',那么当您通过数字文字时,我不会看到'index'可能未定义。你是否可以展示整个函数,或者你从哪里运行'setTimeout()'的一些背景? – nnnnnn 2012-01-05 08:33:04