[英]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.