weibo_其可ers_0
2016-11-05 15:12
如题,代码如下:
<!doctype <!DOCTYPE html>
<html>
<head>
<mata content="text/html;charset=utf-8">
<title>previousSibing返回前一个兄弟节点</title>
</head>
<body>
<ul>
<li>java</li>
<li id="javascript">javascript</li>
<li>PHP</li>
</ul>
<ul>
<li>jquery</li>
<li>ajax</li>
<li>bootstrap</li>
</ul>
<script type="text/javascript">
function get_previousSibling(n){
var x=n.previousSibing;
while(x && x.nodeType!=1){
x=x.previousSibing;
}
return x;
}
var x=document.getElementById("javascript");
document.write(x.nodeName+'<br/>');
document.write(x.innerHTML);
var y=get_previousSibling(x);
document.write(y.nodeName+'<br/>');
document.write(y.innerHTML);
</script>
</body>
</html>
打开浏览器显示:
java
javascript
PHP
jquery
ajax
bootstrap
LI
javascript
究竟是哪出问题了???
真可爱
......
怎么撤销问题? - _ -
.....找到问题所在了。。。。。。previousSbling少了个l.....
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题