我正在使用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
。
如何處理?