大神们帮帮忙..为什么for循环函数跟for循环函数里面的内容结果会不一样
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
window.onload = function(){
var button = document.getElementById("bbb").getElementsByTagName("button");
// function cc(i){
// button[i].onmouseover = function(){
// button[i].style.background = "royalblue";
// }
// button[i].onmouseout = function(){
// button[i].style.background = "#FFC125";
// }
// }
for(var i = 0;i < button.length;i++){
// cc(i);
button[i].onmouseover = function(){
button[i].style.background = "royalblue";
}
button[i].onmouseout = function(){
button[i].style.background = "#FFC125";
}
}
}
</script>
<style type="text/css">
.aaa ul{
text-decoration: none;
}
.aaa ul li{
display: inline;
}
.aaa ul li button{
width: 100px;
height: 50px;
margin: 50px;
background-color: #FFC125;
}
</style>
</head>
<body>
<div class="aaa" id="bbb">
<ul>
<li><button></button></li>
<li><button></button></li>
<li><button></button></li>
</ul>
</div>
</body>
</html>
for循环函数的话可以鼠标移动过去就会变成蓝色,鼠标移走就会变回黄色
如果直接for循环函数里面的内容,鼠标移过去不会有任何变化...........
但是函数里面同样的内容,为什么我不for循环函数,就不行呢
求各位大神为我解答下