改變背景色時為什么一定要調(diào)用函數(shù),不能直接使用對象改變呢?
程序如下:
window.onload = function(){ ? ? ? ? ? ? ? ??
? ? ?// 鼠標(biāo)移動改變背景,可以通過給每行綁定鼠標(biāo)移上事件和鼠標(biāo)移除事件來改變所在行背景色。
? ? ? ? var mytr=document.getElementsByTagName("tr");?
? ? ? ? for(var i=0;i<mytr.length;i++){
? ? ? ? ? ? mytr[i].onmouseover=function(){
myte[i].style.backgroundColor="#f2f2f2";}
mytr[i].onmouseout=function(){
myte[i].style.backgroundColor="#fff";}
? ? ? ? ? ? } ?
}
2015-04-07
?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";
????????????????????}?
????????????????} ?