为啥要写两次previousSibling才会输出上一个节点?
var y=x.previousSibling.previousSibling;
document.write(y.nodeName+"
"+y.innerHTML);
为啥要写两次previousSibling才会输出上一个?
var y=x.previousSibling.previousSibling;
document.write(y.nodeName+"
"+y.innerHTML);
为啥要写两次previousSibling才会输出上一个?
2017-04-23
function get_previousSibling(n){
var x=n.previousSibling;
while(x.nodeType!=1){
x=x.previousSibling;
}
return x;
}
var x=document.getElementsByTagName("li")[1];
document.write(x.nodeName+"<br />"+x.innerHTML+"<br .>");
var y=x.previousSibling.previousSibling;
document.write(y.nodeName+"<br />"+y.innerHTML);
上面的函数应该就过滤掉空白符了吧
举报