function Highlight(){
var tbody = document.getElementById('table').lastChild;
trs = tbody.getElementsByTagName('tr');
for(var i =1;i<trs.length;i++){
trs[i].onmouseover = function(){
this.style.backgroundColor ="#f2f2f2";
}
trs[i].onmouseout = function(){
this.style.backgroundColor ="#fff";
}
}
}循环为什么是从1开始而不是0?
还有就是函数体内为什么要有这行代码?
var tbody = document.getElementById('table').lastChild;
浏览器解析table时,会把table的标签放在table内的tbody标签内,lastChild就是为了获取tbody,用chrome调试就看到了。从1开始,估计第一个是标题列,不需要效果