IE javascript中断或类名问题

IE javascript中断或类名问题,javascript,ajax,Javascript,Ajax,我真的不确定这里的问题是什么,它与铬和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(

我真的不确定这里的问题是什么,它与铬和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(“CertificationalCommentListing”+id).insertBefore(el,next)这一行


好的,这是werid,我做了一些测试,发现了问题。问题在于var el 对于chrome和ff,el为div元素,而ie为null

更奇怪的问题来了。没错,newdiv.firstChild应该是div元素,但我不知道为什么ff和chrome会将其注册为文本元素,显然我的responseText是这样的

<div>blahblah</div>
blahblah

我希望有人明白我在说什么。

您的循环遵循一种奇怪的结构。您正在获取
addpoint.nextSibling
然后查看其
className
属性,仅然后检查节点是否有效。这意味着在循环的最后一次迭代中,当
next
为null时,您试图访问
null
className
属性

while (next) {
    if (next.className != 'commentstyle golduser') break;
    next = next.nextSibling;
}
如果没有更多围绕这个循环的上下文,我不知道
addpoint
如何适应。不必只让循环工作,但是如果确实需要更改
addpoint
,没有理由不能使用此循环构造


关键是,当
next
为空时,您永远不会检查
next.className

也许您应该检查每个兄弟节点的“节点类型”,以确保您只会弄乱HTML元素节点(而不是,例如,注释或文本节点)。您好,先生,我的do循环做得很好,我检查了很多次。我错了,错误在这一行document.getElementById(“CertificationalCommentListing”+id).insertBefore(el,next);在这种情况下,什么是
id
?您共享的代码中没有定义它。是否检查了
document.getElementById()
是否为IE中给定的值返回了有效节点?
while (next) {
    if (next.className != 'commentstyle golduser') break;
    next = next.nextSibling;
}