[英]Javascript setTimeout Parameter Issue (The I'm Using an Anonymous Function Version)
我无法相信我遇到了这个问题。 我的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:这是问题的一个问题。 它无法在我的浏览器(Chrome 16)上运行,我目前无法访问任何其他浏览器。 我不认为这是问题,因为我已经编写了数百次这样的代码。 http://jsfiddle.net/eygraber/NduqY/1/
你的两个函数都被称为'showContent',这意味着当你尝试调用第一个函数时,你真正调用第二个函数,因为第一个函数被覆盖了。
检查索引是否未定义时,请检查条目中的内容。 我打赌这是你要传递给第一个函数的json。
你要两次定义你的showContent
函数......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.