if(theCurrentLength == 0)
{
theCurrentStory++;
theCurrentStory = theCurrentStory % theItemCount;
theStorySummary = theSummaries[theCurrentStory].replace(/"/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = theLeadString;
}
上述属性有什么问题?
答案 0 :(得分:3)
替换poperty有什么问题?
没有问题。问题是
theSummaries[theCurrentStory]
...返回undefined
(或null
,但可能undefined
)。
这表明,如果theSummaries
是一个数组,theItemCount
不等于theSummaries.length
,那么您最终将theCurrentStory
作为无效索引。当您索引具有无效索引的数组时,您将返回undefined
。您可以直接使用theSummaries.length
:
if(theCurrentLength == 0) // <== Does that really make sense?
{
theCurrentStory = (theCurrentStory + 1) % theSummaries.length;
theStorySummary = theSummaries[theCurrentStory].replace(/"/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = theLeadString;
}
或者,如果索引有效,则可以将undefined
存储在数组条目中。唯一可以确定的方法是使用浏览器内置的调试器并逐步执行代码,同时查看变量的值。