现在的位置: 首页 > 综合 > 正文

Table选中一行

2012年12月04日 ⁄ 综合 ⁄ 共 1262字 ⁄ 字号 评论关闭
方法一:
<html> 
  
  <head> 
  <meta   http-equiv="Content-Type"   content="text/html;   charset=gb2312"> 
  <style> 
  .EvenOrOddRow{ 
  background-color:   expression((this.sectionRowIndex%2)?'white':'#E0E0E0'); 
  } 
  
  </style> 
  <script> 
  var   currentActiveRow; 
  function   changeActiveRow(obj) 
  { 
  if(currentActiveRow)   currentActiveRow.style.backgroundColor=""; 
  currentActiveRow=obj; 
  currentActiveRow.style.backgroundColor="Red"; 
  } 
  
  </script> 
  </head> 
  <body> 
  <table   width=100%> 
  <tr   bgcolor=aaaaaa   > 
  <td>Code</td><td>Name</td> 
  </tr> 
  <tr   class="EvenOrOddRow"   onclick="changeActiveRow(this);"> 
  <td>001</td><td>zhangsan</td> 
  </tr> 
  <tr   class="EvenOrOddRow"   onclick="changeActiveRow(this);"> 
  <td>001</td><td>zhangsan</td> 
  </tr> 
  <tr   class="EvenOrOddRow"   onclick="changeActiveRow(this);"> 
  <td>001</td><td>zhangsan</td> 
  </tr> 
  <tr   class="EvenOrOddRow"   onclick="changeActiveRow(this);"> 
  <td>001</td><td>zhangsan</td> 
  </tr> 
  
  </body> 

方法二:

var   curRow;       //全局行号 
  var   curRowId;   //选中行的记录信息的ID 
  var   curColor; 
  function   selectRow(tr1){ 
  if(curRow) 
  { 
  curRow.bgColor=curColor; 
  curColor=tr1.bgColor; 
  tr1.bgColor="#FFE9B3"; 
  }else{ 
  curColor=tr1.bgColor; 
  tr1.bgColor="#FFE9B3"; 
  } 
  curRow=tr1; 
  curRowId=tr1.id; 
  } 
  调用方法:<tr   onclick="selectRow(this)">...

抱歉!评论已关闭.