未捕获的类型错误无法读取未定义的 Javascript 的属性“0”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19146105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
uncaught typeerror cannot read property '0' of undefined Javascript
提问by arabello
here is part of my function code that makes an error on javascript error console ( Google Chrome)
这是我的函数代码的一部分,它在 javascript 错误控制台(谷歌浏览器)上出错
function premuto(x){
if(x.Clickable){
x.Selected = !x.Selected;
if (x.Selected){
x.style.backgroundColor ='lightblue';
y = document.getElementById('spazio');
y.innerHTML = y.innerHTML + x.innerHTML;
sequenza[indice] = x.Number;
indice++;
}
error compares at line "sequenza[indice] = x.Number;"
错误比较在“sequenza[indice] = x.Number;”行
What's wrong?
怎么了?
Thanks
谢谢
回答by Kemal Da?
Your indice
is 0 and sequenza
is undefined
. In javascript it always raises a type error, if you try to reach undefined variable's properties or methods. You should debug your code and see exactly when sequanza becomes undefined
.
你indice
是 0sequenza
是undefined
。在 javascript 中,如果您尝试访问未定义变量的属性或方法,它总是会引发类型错误。您应该调试您的代码,并准确查看 sequanza 何时变为undefined
.