表格鼠标悬停变色。
代码:
var tr=document.getElementsByTagName('tr'); for (var i = 0; i < tr.length; i++) { tr[i].onmouseover=function(){
tr[i].style.backgroundColor="#f2f2f2";
} tr[i].onmouseleave=function(){ tr[i].style.backgroundColor="#fff";
}
}chrome说的是 Uncaught TypeError: Cannot read property 'style' of undefined at HTMLTableRowElement.tr.(anonymous function).onmouseover
但是把tr[i]改为this就可以:
var tr=document.getElementsByTagName('tr'); for (var i = 0; i < tr.length; i++) {
tr[i].onmouseover=function(){ this.style.backgroundColor="#f2f2f2";
}
tr[i].onmouseleave=function(){ this.style.backgroundColor="#fff";
}
}
qq_笑_17
杨__羊羊
随时随地看视频慕课网APP
相关分类