var tbl = document.getElementById("Table2");
var trs = tbl.getElementsByTagName("tr");
for(i=0;i<trs.length;i++)
{
   trs[i].onmouseover = function(e){
      if(this.cc!=true) 
           this.style.backgroundColor='#7FFFD4'; 
   }
   trs[i].onclick = function(e){
       this.cc=!this.cc;
       this.style.backgroundColor = (this.cc==true) ? '#90EE90' : '#e4e8ef';
   }
   trs[i].onmouseout = function(e){
      if(this.cc!=true)
           this.style.backgroundColor='#e4e8ef';
  }
}

解决方案 »

  1.   

    写了就放上来,个个觉得颜色不太好。楼主换一下吧。<HTML>
    <HEAD>
    <TITLE>uu</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=gb2312">
    </HEAD>
    <BODY>
    <div align="center">
      <TABLE id=Table2 cellSpacing=1 cellPadding=0 width="100%" bgColor=#FFFFFF border=0>
        <TR align=middle>
          <TD noWrap width="5%">0</TD>
          <TD noWrap width="5%">O
        </TR>
        <TR align=middle>
          <TD noWrap width="5%">0</TD>
          <TD noWrap width="5%">O
        </TR>
      </TABLE>
    </div>
    <script language="JavaScript" type="text/javascript">
    window.onload = function(){
    var trs = document.getElementById("Table2").getElementsByTagName("tr");
    for (var i = 0; i < trs.length; i++){
      trs[i].setAttribute("flag", false);
      trs[i].onmouseover = _onmouseover;
      trs[i].onclick = _onclick;
      trs[i].onmouseout = _onmouseout;
    }function _onmouseover() {
      if(this.getAttribute("flag") != true){
        this.style.backgroundColor = "#7FFFD4";
      }
    }function _onclick(){
      this.getAttribute("flag") == true ? this.setAttribute("flag", false) : this.setAttribute("flag", true);
      this.getAttribute("flag") == true ? this.style.backgroundColor = "#90EE90" : this.style.backgroundColor = "#e4e8ef";
    }function _onmouseout(){
      if(this.getAttribute("flag") != true){
        this.style.backgroundColor = "#e4e8ef";
      }
    }
    }
    </script></BODY>
    </HTML>
      

  2.   

    非常感谢 KimSoft(革命的小酒天天醉)
    虽然我己经写了一个,但还是你的好。谢谢。