请大家帮忙看看我的元素节点为什么是空的
默认代码
function get_previousSibling(n){
var x=n.previousSibling;
while (x && x.nodeType!=1){
x=x.previousSibling;
}
return x;
}
var x=document.getElementsByTagName("li")[4];
document.write(x.nodeName);
document.write(" = ");
document.write(x.innerHTML);
var y=get_previousSibling(x);
if(y!=null){
document.write("<br />nextsibling: ");
document.write(y.nodeName);
document.write(" = ");
document.write(y.innerHTML);
}else{
document.write("<br>已经是最后一个节点");
}
我的代码
function get_previousSibing(m){
var z=m.previousSibing;
while(z && z.nodeType!=1){
z=z.previousSibing;
}
return z;
}
var z=document.getElementsByTagName("li")[2];
document.write("<br><br>")
document.write(z.nodeName+"="+z.innerHTML);
var d=get_previousSibing(z);
if(d!=null)
{
document.write("<br />previoussibling:"+d.nodeName+" = "+d.innerHTML);
}
else {
document.write("<br>已经是最后一个节点");
}