var tb = document.getElementById('tabID'); // table 的 id var rows = tb.rows; //获取table的行 for(var i = 0; i<rows.length;i++){ if(i%2 == 0){ rows[i].style.backgroundColor="#ffcccc"; //添加鼠标经过事件 rows[i].onmouseover = function(){ this.style.backgroundColor="#ccffff" } //添加鼠标离开事件 rows[i].onmouseout = function(){ this.style.backgroundColor="#ffcccc" } }else{ rows[i].style.backgroundColor="#FFFFFF "; rows[i].onmouseover = function(){ this.style.backgroundColor="#ccffff" } rows[i].onmouseout = function(){ this.style.backgroundColor="#FFFFFF" } } }
js table隔行变色
最新推荐文章于 2024-06-18 18:13:04 发布