0x800a138f - JavaScript运行时错误:无法获取属性'replace'未定义或空引用的
0x800a138f - JavaScript runtime error: Unable to get property 'replace' of undefined or null reference
if(theCurrentLength == 0)
{
theCurrentStory++;
theCurrentStory = theCurrentStory % theItemCount;
theStorySummary = theSummaries[theCurrentStory].replace(/"/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = theLeadString;
}
上述属性有什么问题?
replace属性有什么问题?
没有问题。问题是
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
存储在数组项中。唯一确定的方法是使用浏览器内置的调试器,并逐步检查代码,同时查看变量的值。
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Replace()产生“;未捕获的类型错误:未定义的不是函数“;当与零一起使用时
- Dojo lang.replace - 如何提供默认值,而不是“未定义”
- Jquery无法调用未定义的方法replace
- remote.getGlobal()返回“未定义”;后window.location.replace()
- 0x800a138f - JavaScript运行时错误:无法获取属性'replace'未定义或空引用的
- TypeError:表达式'的结果;input.replace'[未定义]不是函数