为什么我这样写页面崩溃了
function get_previousSibling(i){ var a = i.previousSibling; while(a && a.nodeType != 1){ a= i.previousSibling; } return a; } var b = document.getElementsByTagName('li')[1]; document.write(b.nodeName); document.write(' = '); document.write(b.innerHTML+'<br>'); var c = get_previousSibling(b); if(c!=null){ document.write(c.nodeName); document.write(' = '); document.write(c.innerHTML); }else{ document.write('这个是空节点'); }
我这样写页面崩溃了,我感觉没有啥问题.....看不出来问题,然后我把
while(a && a.nodeType != 1)
改成
while(i && i.nodeType != 1)
就不会崩溃 还可以运行