慕哥2132778
2019-07-28 16:49
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<ul id="u1">
<li id="a">杭州</li>
<li id="b">上海</li>
<li id="c">南京</li>
</ul>
<ul id="u2">
<li id="d">普陀山</li>
<li id="e">九华山</li>
<li id="f">五台山</li>
</ul>
<script>
function get_nextSibling(n){
var x = n.nextSiling;
while(x.nodeType != 1)
{
x=x.nextSiling;
}
return x;
}
var x = document.getElementsByTagName("li")[0];
document.write(x.nodeName);
document.write("=");
document.write(x.innerHTML);
var y = get_nextSibling(x);
document.write("<br>nextSiling:");
document.write(y.nodeName);
document.write("=");
document.write(y.innerHTML);
</script>
</body>
</html>
nextSibling写错了。
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题