gpt4 book ai didi

javascript - 无法读取未定义的属性 'length'

转载 作者:行者123 更新时间:2023-12-02 18:36:13 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com