解决方案 »

  1.   

    不需要js设置事件,只用CSS就行<style type="text/css">
    td:hover  { background:#ccffff; }
    </style>
    ---------------------------------------
    <table>
       <tr>
           <td>我是第一行第一列</td>
           <td>我是第一行第二列</td>
           <td>我是第一行第三列</td>
       </tr>
     </table> 
      

  2.   

    <table>
      <tr>
          <td onmouseover="this.style.background='#888'" onmouseout="this.style.background=''">我是第一行第一列</td>
          <td onmouseover="this.style.background='#888'" onmouseout="this.style.background=''">我是第一行第二列</td>
          <td onmouseover="this.style.background='#888'" onmouseout="this.style.background=''">我是第一行第三列</td>
      </tr>
    </table>
      

  3.   

    1L代码简单,但不兼容低版本浏览器,好像IE8以下无效
    2L代码兼容所有浏览器,就是写在html里面麻烦了点。var tds = document.getElementsByTagName('td');
    for(var i=0;i<tds.length;i++){
        tds[i].onmouseover = function(){
            this.style.background = 'red'
        }
        tds[i].onmouseout = function(){
            this.style.background = ''
        }
    }