我不确定这里的问题是什么,它适用于chrome和ff,但不是ie。
var newdiv = document.createElement("div");
newdiv.innerHTML = xhr.responseText;
el = newdiv.firstChild.nextSibling;
var next;
do{
next = addpoint.nextSibling;
if(next.className != "commentstyle golduser") break;
}while(addpoint = next);
document.getElementById("testimonialcommentlisting"+id).insertBefore(el,next);
错误在此行document.getElementById(“testimonialcommentlisting”+ id).insertBefore(el,next);
**UPDATE**
好吧,这是不可思议的,我做了一些测试,我发现了问题。问题出在var el
对于chrome和ff el是div元素,而ie是null。
这是一个棘手的问题。右边,newdiv.firstChild应该是div元素,但我不知道为什么ff和chrome将它注册为文本元素,显然我的responseText是这样的
<div>blahblah</div>
我希望有人理解我在说什么。
答案 0 :(得分:1)
你的循环遵循奇怪的结构。您正在提取addpoint.nextSibling
,然后查看其className
属性,只有 然后 检查该节点是否有效。这意味着在循环的最后一次迭代中,当next
为空时,您尝试访问className
的{{1}}属性。
null
如果没有周围环绕这个循环的更多上下文,我不知道while (next) {
if (next.className != 'commentstyle golduser') break;
next = next.nextSibling;
}
如何适应。没有必要只是让循环工作,但如果你确实需要改变addpoint
没有理由使用这种循环结构你不能这样做。
关键是,当addpoint
为空时,您永远不会检查next.className
。