当前位置: 代码迷 >> JavaScript >> js报表光棒效果3种解决方案,支持动态生成表格
  详细解决方案

js报表光棒效果3种解决方案,支持动态生成表格

热度:105   发布时间:2012-11-06 14:07:00.0
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 = '';
      };
}
  相关解决方案