<script language="javascript">var tables=["table1","table2"];//在这里填上表格ID,可以实现若干个表格同时改变for(var i=0;i<tables.length;i++){
var tb = document.getElementById(tables[i]);
tb.onmouseover=function(){
var tr = getTr(event.srcElement);
if(tr==null)return;
ChangeBackColor(tr.rowIndex,"#aaaaaa");
}

tb.onmouseout=function(){
var tr = getTr(event.srcElement);
if(tr==null)return;
ChangeBackColor(tr.rowIndex,"#ffffff");
}
}function ChangeBackColor(rowIndex,backColor){
for(var i=0;i<tables.length;i++)
document.getElementById(tables[i]).rows[rowIndex].style.backgroundColor=backColor;
}function getTr(obj){
if(obj.tagName!="TD") return null;
return obj.parentElement;
}
</script>

解决方案 »

  1.   

    你好,非常感谢你的回帖 
     请问,tb.onmouseout=function(){
    这段是什么意思,这个代码应该加到哪里。
      

  2.   

    我将2个table都指定了id,可是
    提示tb为空或者不是对象
    <table id="table1"..........
    <table id="table2"..........
      

  3.   

    把代码放在你表格代码后面,或者直接放到</html>以后
      

  4.   

    tb.onmouseout=function()
    这个的意思是。tb的一个事件,onmouseout,这个事件触发的函数是后面的function();