2013-01-21 54 views
0

我在一個我的javascript函數中使用以下for循環來在我的應用程序中創建一個數據行。Javascript:Chrome爲[object HtmlDivElement]提供[object text]

for (var j = 0, length = contentsArray.length; j < length; j++) { 
     //get the control for the node at this index 
     contentControl = contentControlDef.getControlForObjectAtContainerIndex(contentsArray[j], j); 
     //repopulate node; call overwriteDomNode(instanceDom, contentsArray, index); 
      contentControl.overwriteDomNode(contentsDom.childNodes[j], contentsArray, j); 
    } 

在這種情況下,contentsDom.childNodes[object HtmlDivElements]在IE和FF的陣列。但在Chrome中,這是不同的。它在數組中具有相同數量的元素。但它有一個接一個地有[object text][object HtmlDivElement]。它應該有所有的HtmlDivElements。有誰知道這是爲什麼發生在鉻?

回答

2

更改代碼:

for (var j = 0, length = contentsArray.length; j < length; j++) { 
    //get the control for the node at this index 
    contentControl = contentControlDef.getControlForObjectAtContainerIndex(contentsArray[j], j); 
    //repopulate node; call overwriteDomNode(instanceDom, contentsArray, index); 
    contentControl.overwriteDomNode(contentsDom.children[j], contentsArray, j); 
} 

childNodes回報也是文本節點。如果您不需要文本節點,請使用children

+1

非常感謝Minko ..它像一個魅力! :d –

相關問題