It means you've tried to insert a DOM node into a place in the DOM tree where it cannot go.(这意味着您已尝试将DOM节点插入到DOM树中无法访问的位置。)
The most common place I see this is on Safari which doesn't allow the following:(我看到的最常见的地方是Safari,它不允许以下内容:)
document.appendChild(document.createElement('div'));
Generally, this is just a mistake where this was actually intended:(一般来说,这只是一个错误,实际上是这样的:)
document.body.appendChild(document.createElement('div'));
Other causes seen in the wild (summarized from comments):(在野外看到的其他原因(从评论中总结):)
- You are attempting to append a node to itself(您正在尝试将节点附加到自身)
- You are attempting to append null to a node(您正在尝试将null附加到节点)
- You are attempting to append a node to a text node.(您正在尝试将节点附加到文本节点。)
- Your HTML is invalid (eg failing to close your target node)(您的HTML无效(例如,无法关闭目标节点))
- The browser thinks the HTML you are attempting to append is XML (fix by adding
<!doctype html>
to your injected HTML, or specifying the content type when fetching via XHR)(浏览器认为您尝试附加的HTML是XML(通过向注入的HTML添加<!doctype html>
或通过XHR获取时指定内容类型来修复))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…