这个就是鼠标离开悬浮时改变当前tr的CSS类

解决方案 »

  1.   

    var rows = document.getElementsByTagName('tr'); //获取所有行
    for (var i=0;i <rows.length;i++){ //循环每一行
    rows[i].onmouseover = function(){ this.className += 'altrow'; //鼠标经过时当前行的样式

    rows[i].onmouseout = function(){ this.className = this.className.replace('altrow',''); 鼠标离开时当前行的样式
      

  2.   

    谢谢楼上两位,其实你们说的我也理解点,
    就是className与this.className.replace(“altrow","")的属性是什么意思呀,replace("altrow","")意思是不是说
    鼠标离开时,颜色改为空。 this.className+="altrow"为什么还要再加上altrow。问的可能有点白痴,希望大家不要见笑!
      

  3.   

    this.className.replace(“altrow","")//去掉样式
    this.className+='altrow'//因为程序保证了只有一行有样式 所以mouseover的时候this.className肯定是没有样式的 即this.className=="" 在此this.className+='altrow'其实与this.className='altrow'是一样的
      

  4.   

    this.className+="altrow"这个是原本的样式再加上“altrow”动态变色样式。
    className与this.className.replace(“altrow","")就是把添加进去的“altrow”转化为空。就是删除altrow样式,恢复到以前的样式。