如果我有 :
<div id="mc"></div>
和以下ajax.responseText:
<div id="mc">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
最后是我的 Javascript 代码:
var div = document.createElement("div");
div.innerHTML = ajax.responseText;
var divChildren = div.children;
for(var i = 0; i < divChildren.length; i++) {
var root = divChildren[i];
var children = root.children;
var documentRoot = document.getElementById(root.id||"$");
if(documentRoot) {
var node = null;
for(var j = 0; j < children.length; j++) {
node = children[j];
documentRoot.appendChild(node);
}
}
}
为什么结果是?:
<div id="mc">
<div>1</div>
<div>3</div>
<div>5</div>
</div>