我正在尝试使用此函数将新值插入到数组元素的属性中 .
function updateLabel (e) {
var labelRow = e.parentNode.parentNode.rowIndex;
var fieldPosition = labelRow + 1;
var index = labelRow -1;
var newLabel = document.getElementsByTagName('input')[fieldPosition].value;
alert(newLabel);
xyarr[xyarr.index].label = newLabel;
}
当我提醒(newLabel);它会提醒我要存储的值,但是当我到达函数的最后一行时,我得到错误:Uncaught TypeError:无法设置undefined的属性'label'
1 回答
我没有看到
xyarr.index
的定义 . 你的意思是使用index
吗?错误消息"Cannot set property 'label' of undefined"似乎表明您尝试从阵列中检索的对象(即xyarr[xyarr.index]
)未定义 .您还可以尝试使用以下索引器语法来尝试设置属性: