我正在客户的 WooCommerce/WordPress 网上商店上运行一个新插件,但它没有按预期工作。浏览器控制台给我这个错误:
Uncaught TypeError: Cannot read property '1' of null
at Object.success (yith-wcp-frontend.min.js:1)
at i (jquery.js:2)
at Object.fireWith [as resolveWith] (jquery.js:2)
at y (jquery.js:4)
at XMLHttpRequest.c (jquery.js:4)
我已经“漂亮地打印”了该错误,这将为我提供正确的行:
Uncaught TypeError: Cannot read property '1' of null
at Object.success (yith-wcp-frontend.min.js:formatted:206)
at i (jquery.js:2)
at Object.fireWith [as resolveWith] (jquery.js:2)
at y (jquery.js:4)
at XMLHttpRequest.c (jquery.js:4)
第 206 行如下所示:
我从来没有真正理解这些“无法读取 null 的属性‘1’”错误,尤其是这个错误。有人知道这里出了什么问题吗?
这是特定页面的链接:http://wqd.nl/3IFd
在“Kleurkeuze”下面的选择列表中选择某些内容时会弹出错误。
最佳答案
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
如果没有匹配项,则匹配返回 null。所以它会抛出一个错误,因为您试图对 null 进行索引。在尝试使用 [1] 访问该元素之前,您应该检查该元素是否是一个数组,并且至少有 2 个元素。
关于javascript - 无法读取我的 WordPress 插件上 null 的属性 '1',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47664532/