输出第一个元素的前一个元素,没有提示?
<script type="text/javascript">
function get_previousSibling(n){
var y=n.previousSibling;
document.write(y.nodeType);
while (y && y.nodeType!=1){
y=y.previousSibling;
document.write(y.nodeType);
}
return y;
}
var x=document.getElementsByTagName("li")[0];
//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>已经是第一个节点");
}
</script>
为啥没执行“这是第一个元素”的输出?