移動鼠標改變背景顏色,以下代碼存在什么問題?
window.onload = function(){
? ? ?// 鼠標移動改變背景,可以通過給每行綁定鼠標移上事件和鼠標移除事件來改變所在行背景色。
? ? ?var tr=document.getElementsByTagName("tr");
? ? ? ? ? for(var i= 0;i<tr.length;i++)
? ? ? ? ? {
? ? ? ? ? tr[i].onmouseover=function(){
? ? ? ? ? ? tr[i].style.backgroundColor="#f2f2f2";}
? ? ? ? ? tr[i].onmouseout=function(){
? ? ? ? ? ? tr[i].style.backgroundColor="#fff";}
? ? ? ? ? }
? ? ? }
2017-05-06
貌似是不能用數組[i].onmouseover這個方法
2017-05-05
應該使用color屬性,backgroundColor不會改變字體的顏色