js表格光棒效果3种解决方案,支持动态生成表格
var table = document.getElementById(table_id);var rows = table.getElementsByTagName("tr");// 第一种方法for (i = 1; i < rows.length; i++) {// 0 is start var srcBgColor = null; rows[i].onmouseover = function() { srcBgColor = this.style.backgroundColor; this.style.backgroundColor = 'red'; }; rows[i].onmouseout = function() { this.style.backgroundColor = srcBgColor; };}// 第二种方法for (i = 1; i < rows.length; i++) {// 0 is start var srcBgColor = rows[i].style.backgroundColor; rows[i].onmouseover = function() { this.style.backgroundColor = 'red'; }; rows[i].onmouseout = function() { this.style.backgroundColor = srcBgColor; };}// 第三种方法for (i = 1; i < rows.length; i++) {// 0 is start rows[i].onmouseover = function() { this.style.backgroundColor = 'red'; }; rows[i].onmouseout = function() { this.style.backgroundColor = ''; };}