循環(huán)為什么是從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"; }? }?? ?}
循環(huán)為什么是從1開始而不是0?
還有就是函數(shù)體內(nèi)為什么要有這行代碼?
var tbody = document.getElementById('table').lastChild;
2015-10-12
瀏覽器解析table時(shí),會(huì)把table的標(biāo)簽放在table內(nèi)的tbody標(biāo)簽內(nèi),lastChild就是為了獲取tbody,用chrome調(diào)試就看到了。從1開始,估計(jì)第一個(gè)是標(biāo)題列,不需要效果