for (i = 0; i < count; i++) {
var item = list.childNodes[i]._value;
var RecID = item.RecID;
var zerocount = 5 - RecID.length;
var PicZeros = "";
for (k = 0; k < zerocount; k++)
PicZeros += "0";
var url = "/p_" + PicZeros + RecID + "_01.jpg";
}
我收到此错误:
TypeError: Cannot read property 'length' of undefined
我不明白如何解决这个问题?
最佳答案
好吧,在某些时候,list.childNodes[i]._value.RecID
会给你一个未定义的值。
这是您问题的根本原因,您需要解决它。
也许count
是错误的,也许你已经错误地填充了列表,我们无法从给出的代码中真正看出。
And, as an aside, I'm almost certain there's better ways to left-pad a string with
0
characters than with a loop. Something like:
var url = "/p_" + "00000".substring(RecID.length) + RecID + "_01.jpg";
would be better.
关于javascript - 无法读取未定义的属性 'length',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17290600/