如果是这个来控制表格背景颜色~~
那么原来有背景色的~在鼠标移到这个的时候用的是新的颜色~~~移走要保持原来的颜色怎么办?~~<script type="text/javascript">
var t=document.getElementById("tab");
var tr=t.rows;
for(i=0;i<tr.length;i++){
tr[i].onmouseover=Function("c("+i+")");
tr[i].onmouseout=Function("r("+i+")");
}
function c(n){
    if(n+1>tr.length-1){n=n-1}
    tr[n].style.background='#F00';
    tr[n+1].style.background='#F00';
}
function r(n){
    if(n+1>tr.length-1){n=n-1}
    tr[n].style.background='none';
    tr[n+1].style.background='none';
}
</script>

解决方案 »

  1.   


    <table id="tab">
    <tr><td>xx</td></tr>
    <tr><td>xx</td></tr>
    <tr><td>xx</td></tr>
    </table>
    <script type="text/javascript">
    var t=document.getElementById("tab");
    var tr=t.rows;
    var bg=bg1=null;
    for(i=0;i<tr.length;i++){
    tr[i].onmouseover=Function("c("+i+")");
    tr[i].onmouseout=Function("r("+i+")");
    }
    function c(n){
        if(n+1>tr.length-1){n=n-1}
    bg = tr[n].style.background;
    bg1 = tr[n+1].style.background;
    tr[n].style.background='#F00';
        tr[n+1].style.background='#F00';
    }
    function r(n){
        if(n+1>tr.length-1){n=n-1}
        tr[n].style.background=bg;
        tr[n+1].style.background=bg1;
    }
    </script>
      

  2.   

    L@_@K
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
      <table id="tab">
    <tr style="background-color: blue;">
    <td>1</td>
    <td>2</td>
    <td>3</td>
    </tr>
    <tr style="background-color: yellow;">
    <td>a</td>
    <td>b</td>
    <td>c</td>
    </tr>
    <tr style="background-color: green;">
    <td>x</td>
    <td>y</td>
    <td>z</td>
    </tr>
      </table>
      <script type="text/javascript">
    var t=document.getElementById("tab");
    var tr=t.rows;
    for(i=0;i<tr.length;i++){
    tr[i].onmouseover=Function("c("+i+")");
    tr[i].onmouseout=Function("r("+i+")");
    }
    function c(n)
    {
        if(n == tr.length-1) n--;

    tr[n].style.originalBgColor = tr[n].style.backgroundColor;
    tr[n+1].style.originalBgColor = tr[n+1].style.backgroundColor;    tr[n].style.backgroundColor = '#F00';
        tr[n+1].style.backgroundColor = '#F00';
    }
    function r(n)
    {
        if(n == tr.length-1) n--;    tr[n].style.backgroundColor = tr[n].style.originalBgColor;
        tr[n+1].style.backgroundColor = tr[n+1].style.originalBgColor;
    }
    </script>
     </body>
    </html>