我有一个包含子项的文档片段,我想循环(如果可能)。这会导致错误“无法读取 null 的属性‘xxx’”。
我如何测试是否会出现这种情况?
最佳答案
您可能需要执行以下操作:
if ((documentFragment !== null) && documentFragment.hasOwnProperty('xxx')) {
// handle property xxx of documentFragment as required
}
关于javascript - "Cannot read property ' xxx ' of null",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2711843/