我正在使用jQuery来操作我的项目中的DOM。我有类方法,即是这样工作的:replaceWith jQuery方法后,父节点为null
<!-- language: lang-js -->
var template = this._Template.split('{0}');
var content = template[0] + this._Content + template[1];
if (!this._BlockNode) {
this._BlockNode = $(content);
this._ParentNode.append(this._BlockNode);
}
else {
this._BlockNode.replaceWith(content);
}
一切都是这种方法的第一个呼叫OK,因为它创建节点,并将其追加到父节点。第二个电话(使用replaceWith()
方法)也可以。但是之后它的属性this._BlockNode[0].parentNode
为空。因此,当我第三次打电话时,replaceWith()
与新的_.BlockNode
一起使用,而不使用.parentNode
属性,因此此检查不会替换节点的内容:if (!isDisconnected(this[0])) { //line 5910 in jQuery 1.8.3
。
如何处理?