不知道哪里出了问题,各位大佬帮忙看看,最后应该获取到两个ol下的class节点的,但是运行的时候显示为0个,而且也没有变红色。。。。在线等,急
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
//node.getElementsByClass()
function elementsByClassName(node, classStr){
var nodes = node.getElementsByTagName("*");
var arr = [];
for(var i = 0; i < nodes.length; i++){
if(nodes[i].calssName === classStr){
arr.push(nodes[i]);
}
}
return arr;
}
window.onload = function(){
var oL = document.getElementById("ol1");
var nodes = elementsByClassName(oL, "box");
alert(nodes.length);
for(var i = 0; i < nodes.length; i++){
nodes[i].style.backgroundColor = "red";
}
}
</script>
</head>
<body>
<ul id = "ul1">
<li>111</li>
<li class="box">111</li>
<li>111</li>
<li>111</li>
<li class="box">111</li>
<li name = "hello">111</li>
<li class="box" name = "hello">111</li>
<div class="box" name = "hello">div</div>
</ul>
<input type="text" name="hello" >
<span name = "hello">111</span>
<ol id="ol1">
<li>222</li>
<li class="box">222</li>
<li class="box">222</li>
<li>222</li>
</ol>
</body>
</html>