【发布时间】:2014-11-28 13:48:20
【问题描述】:
请原谅我没有说清楚,但是这个脚本真的很长。当我启用它时,我在 Chrome 的控制台中收到此错误。
未捕获的类型错误:无法读取未定义的属性“substr”
这里是读取的代码的 sn-p。
var formIddd = $('select[class~="FormField"]').get(numSelec).name.substr($('select[class~="FormField"]').get(numSelec).name.length-3,2);
我在 google 上查找了 substr,它似乎是一个已知属性。我也找到了课程。我玩过长度,但仍然卡住了。在 BigCommerce 进行更新之前,它一直有效。
非常感谢任何建议,干杯。
【问题讨论】:
-
仔细阅读错误。 “无法读取未定义的属性 'substr'”。这意味着
name未定义,而不是substr。 -
调试:
var elems = $('select[class~="FormField"]'); console.log(numSelec, elems.length, elems.get(numSelec)); -
@AmitJoki 如果索引超出范围,则意味着
get(numSelec) would beundefined, which would result in the errorCannot read property 'name' of undefined. Soget(numSelec)` 的结果会返回一些东西,但它没有name属性。 -
还有你的问题:
numSelec是undefined。 -
您需要显示更多代码,执行顺序有问题。
标签: javascript jquery bigcommerce