改变背景色的问题
var trs = document.getElementsByTagName("tr");
changeColor(trs);
//循环在里面
function changeColor(trs){
for(var i=0;i<trs.length;i++){
var tr = trs[i];
tr.onmouseover = function(){
tr.style.backgroundColor = "#f2f2f2";
}
tr.onmouseout = function(){
tr.style.backgroundColor = "#fff";
}
}
}var trs = document.getElementsByTagName("tr");
//循环在外面
for(var i=0;i<trs.length;i++){
changeColor(trs[i]);
}
function changeColor(tr){
tr.onmouseover = function(){
tr.style.backgroundColor = "#f2f2f2";
}
tr.onmouseout = function(){
tr.style.backgroundColor = "#fff";
}
}循环在里面始终只有最后一行会有改背景色的效果,而循环在外面3行都有。为什么?