javascript - "Cannot read property ' xxx ' of null"

标签 javascript null typeerror

我有一个包含子项的文档片段,我想循环(如果可能)。这会导致错误“无法读取 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/

相关文章:

javascript - 如何使用 javascript/jQuery 检查/取消选中 HTML CheckBoxFor

powershell - 如何在 PowerShell 中为变量分配空值?

javascript - AngularJs 为什么在 ng-disabled 函数上 undefined object ?

python - 使用 pywinauto 连接到第二个应用程序

javascript - 反向排序列表上的 lodash searchIndex

JavaScript:如何在数组中存储对象?

javascript - "Professional XMPP Programming with JavaScript and jQuery"的示例 3 - 连接按钮不起作用

c - 为什么 C 不使用特殊的转义字符串终止字符终止字符串?

我可以在需要 int* 的地方传递 NULL 吗?

javascript - 未捕获的类型错误 : number is not a function