循環為什么是從1開始而不是0?
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;
2015-10-12
瀏覽器解析table時,會把table的標簽放在table內的tbody標簽內,lastChild就是為了獲取tbody,用chrome調試就看到了。從1開始,估計第一個是標題列,不需要效果